From 86afe6e3f95b82d1935dcac19b67cb03455797d0 Mon Sep 17 00:00:00 2001 From: Tom Meagher Date: Fri, 12 May 2023 09:33:26 -0400 Subject: [PATCH] feat: improve error code type --- .changeset/long-brooms-jog.md | 5 +++++ src/types/eip1193.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/long-brooms-jog.md diff --git a/.changeset/long-brooms-jog.md b/.changeset/long-brooms-jog.md new file mode 100644 index 0000000000..8833df5790 --- /dev/null +++ b/.changeset/long-brooms-jog.md @@ -0,0 +1,5 @@ +--- +"viem": patch +--- + +Improved RpcError code types. diff --git a/src/types/eip1193.ts b/src/types/eip1193.ts index 734732d916..1cd9e2d7fc 100644 --- a/src/types/eip1193.ts +++ b/src/types/eip1193.ts @@ -23,11 +23,17 @@ export type EIP1193Provider = Requests & Events ////////////////////////////////////////////////// // Errors +// rome-ignore format: no formatting +export type RpcErrorCode = + // https://eips.ethereum.org/EIPS/eip-1193#provider-errors + | 4_001 | 4_100 | 4_200 | 4_900 | 4_901 + // https://eips.ethereum.org/EIPS/eip-1474#error-codes + | -32700 | -32600 | -32601 | -32602 | -32603 | -32000 | -32001 | -32002 | -32003 | -32004 | -32005 | -32006 export class RpcError extends Error { - code: number + code: RpcErrorCode | (number & {}) details: string - constructor(code: number, message: string) { + constructor(code: RpcErrorCode | (number & {}), message: string) { super(message) this.code = code this.details = message