Skip to content

Commit aa42de1

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 aa42de1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/classes.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ 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 {
9+
DataWithOptionalCause,
10+
OptionalDataWithOptionalCause,
11+
} from './utils';
912
import { serializeCause } from './utils';
1013

1114
export type { SerializedJsonRpcError };
@@ -16,7 +19,9 @@ export type { SerializedJsonRpcError };
1619
*
1720
* Permits any integer error code.
1821
*/
19-
export class JsonRpcError<Data extends DataWithOptionalCause> extends Error {
22+
export class JsonRpcError<
23+
Data extends OptionalDataWithOptionalCause,
24+
> extends Error {
2025
public code: number;
2126

2227
public data?: Data;

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ 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 = undefined | DataWithOptionalCause;
39+
3240
const FALLBACK_ERROR_CODE = errorCodes.rpc.internal;
3341
const FALLBACK_MESSAGE =
3442
'Unspecified error message. This is a bug, please report it.';

0 commit comments

Comments
 (0)