Skip to content

Commit 20b7920

Browse files
committed
types: Make Data type-parameter optional in JsonRpcError
This is in order to provide backwards-compatibility with code implemented towards v5.0.0.
1 parent ab0ebca commit 20b7920

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/classes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
import { isPlainObject } from '@metamask/utils';
66
import safeStringify from 'fast-safe-stringify';
77

8-
import type { DataWithOptionalCause } from './utils';
8+
import type { DataWithOptionalCause, OptionalDataWithOptionalCause } from './utils';
99
import { serializeCause } from './utils';
1010

1111
export type { SerializedJsonRpcError };
@@ -16,7 +16,7 @@ export type { SerializedJsonRpcError };
1616
*
1717
* Permits any integer error code.
1818
*/
19-
export class JsonRpcError<Data extends DataWithOptionalCause> extends Error {
19+
export class JsonRpcError<Data extends OptionalDataWithOptionalCause> extends Error {
2020
public code: number;
2121

2222
public data?: Data;

src/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ export type DataWithOptionalCause =
2929
cause: unknown;
3030
};
3131

32+
/**
33+
* A data object, that must be either:
34+
*
35+
* - A valid DataWithOptionalCause value.
36+
* - undefined.
37+
*/
38+
export type OptionalDataWithOptionalCause =
39+
| undefined
40+
| DataWithOptionalCause;
41+
3242
const FALLBACK_ERROR_CODE = errorCodes.rpc.internal;
3343
const FALLBACK_MESSAGE =
3444
'Unspecified error message. This is a bug, please report it.';

0 commit comments

Comments
 (0)