File tree 2 files changed +11
-1
lines changed
2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import type {
2
2
Json ,
3
3
JsonRpcError as SerializedJsonRpcError ,
4
4
} from '@metamask/utils' ;
5
- import { isPlainObject } from '@metamask/utils' ;
5
+ import { hasProperty , isObject , isPlainObject } from '@metamask/utils' ;
6
6
import safeStringify from 'fast-safe-stringify' ;
7
7
8
8
import type { OptionalDataWithOptionalCause } from './utils' ;
@@ -19,6 +19,10 @@ export type { SerializedJsonRpcError };
19
19
export class JsonRpcError <
20
20
Data extends OptionalDataWithOptionalCause ,
21
21
> extends Error {
22
+
23
+ // This can be removed when tsconfig lib and/or target have changed to >=es2022
24
+ public cause : OptionalDataWithOptionalCause ;
25
+
22
26
public code : number ;
23
27
24
28
public data ?: Data ;
@@ -36,6 +40,11 @@ export class JsonRpcError<
36
40
this . code = code ;
37
41
if ( data !== undefined ) {
38
42
this . data = data ;
43
+ if ( isObject ( data ) && hasProperty ( data , 'cause' ) ) {
44
+ this . cause = isObject ( data . cause )
45
+ ? data ?. [ 'cause' ]
46
+ : undefined ;
47
+ }
39
48
}
40
49
}
41
50
Original file line number Diff line number Diff line change 3
3
"esModuleInterop" : true ,
4
4
"exactOptionalPropertyTypes" : true ,
5
5
"forceConsistentCasingInFileNames" : true ,
6
+ // Remove custom `cause` field from JsonRpcError when updating
6
7
"lib" : [" ES2020" ],
7
8
"module" : " CommonJS" ,
8
9
"moduleResolution" : " node" ,
You can’t perform that action at this time.
0 commit comments