File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import type {
22 Json ,
33 JsonRpcError as SerializedJsonRpcError ,
44} from '@metamask/utils' ;
5- import { isPlainObject } from '@metamask/utils' ;
5+ import { hasProperty , isObject , isPlainObject } from '@metamask/utils' ;
66import safeStringify from 'fast-safe-stringify' ;
77
88import type { OptionalDataWithOptionalCause } from './utils' ;
@@ -19,6 +19,10 @@ export type { SerializedJsonRpcError };
1919export class JsonRpcError <
2020 Data extends OptionalDataWithOptionalCause ,
2121> extends Error {
22+
23+ // This can be removed when tsconfig lib and/or target have changed to >=es2022
24+ public cause : OptionalDataWithOptionalCause ;
25+
2226 public code : number ;
2327
2428 public data ?: Data ;
@@ -36,6 +40,11 @@ export class JsonRpcError<
3640 this . code = code ;
3741 if ( data !== undefined ) {
3842 this . data = data ;
43+ if ( isObject ( data ) && hasProperty ( data , 'cause' ) ) {
44+ this . cause = isObject ( data . cause )
45+ ? data ?. [ 'cause' ]
46+ : undefined ;
47+ }
3948 }
4049 }
4150
Original file line number Diff line number Diff line change 33 "esModuleInterop" : true ,
44 "exactOptionalPropertyTypes" : true ,
55 "forceConsistentCasingInFileNames" : true ,
6+ // Remove custom `cause` field from JsonRpcError when updating
67 "lib" : [" ES2020" ],
78 "module" : " CommonJS" ,
89 "moduleResolution" : " node" ,
You can’t perform that action at this time.
0 commit comments