Skip to content

Commit

Permalink
feat: propagate data.cause as cause in JsonRpcError constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed May 12, 2024
1 parent 1c1ffa9 commit d4f192d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ module.exports = {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 92.64,
branches: 93.05,
functions: 94.44,
lines: 92.85,
statements: 92.85,
lines: 92.96,
statements: 92.96,
},
},

Expand Down
8 changes: 7 additions & 1 deletion src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
Json,
JsonRpcError as SerializedJsonRpcError,
} from '@metamask/utils';
import { isPlainObject } from '@metamask/utils';
import { hasProperty, isObject, isPlainObject } from '@metamask/utils';
import safeStringify from 'fast-safe-stringify';

import type { OptionalDataWithOptionalCause } from './utils';
Expand All @@ -19,6 +19,9 @@ export type { SerializedJsonRpcError };
export class JsonRpcError<
Data extends OptionalDataWithOptionalCause,
> extends Error {
// This can be removed when tsconfig lib and/or target have changed to >=es2022
public cause: OptionalDataWithOptionalCause;

public code: number;

public data?: Data;
Expand All @@ -36,6 +39,9 @@ export class JsonRpcError<
this.code = code;
if (data !== undefined) {
this.data = data;
if (isObject(data) && hasProperty(data, 'cause') && isObject(data.cause)) {

Check failure on line 42 in src/classes.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Replace `isObject(data)·&&·hasProperty(data,·'cause')·&&·isObject(data.cause)` with `⏎········isObject(data)·&&⏎········hasProperty(data,·'cause')·&&⏎········isObject(data.cause)⏎······`
this.cause = data.cause;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
// Remove custom `cause` field from JsonRpcError when updating
"lib": ["ES2020"],
"module": "CommonJS",
"moduleResolution": "node",
Expand Down

0 comments on commit d4f192d

Please sign in to comment.