diff --git a/src/classes.ts b/src/classes.ts index dbd6429..b7c3540 100644 --- a/src/classes.ts +++ b/src/classes.ts @@ -5,7 +5,7 @@ import type { import { isPlainObject } from '@metamask/utils'; import safeStringify from 'fast-safe-stringify'; -import type { DataWithOptionalCause } from './utils'; +import type { DataWithOptionalCause, OptionalDataWithOptionalCause } from './utils'; import { serializeCause } from './utils'; export type { SerializedJsonRpcError }; @@ -16,7 +16,7 @@ export type { SerializedJsonRpcError }; * * Permits any integer error code. */ -export class JsonRpcError extends Error { +export class JsonRpcError extends Error { public code: number; public data?: Data; diff --git a/src/utils.ts b/src/utils.ts index 192d7a8..40a4677 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -29,6 +29,16 @@ export type DataWithOptionalCause = cause: unknown; }; +/** + * A data object, that must be either: + * + * - A valid DataWithOptionalCause value. + * - undefined. + */ +export type OptionalDataWithOptionalCause = + | undefined + | DataWithOptionalCause; + const FALLBACK_ERROR_CODE = errorCodes.rpc.internal; const FALLBACK_MESSAGE = 'Unspecified error message. This is a bug, please report it.';