From a41a46270d225e63a5db3b5b8ea93ff326c2d547 Mon Sep 17 00:00:00 2001 From: Aaron Choo Date: Wed, 3 Jul 2024 14:58:19 +0800 Subject: [PATCH] fix: update `wrap` to handle more wallet errors --- src/wallet/wallets/WalletError.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallets/WalletError.ts b/src/wallet/wallets/WalletError.ts index bada7cf5..4215a988 100644 --- a/src/wallet/wallets/WalletError.ts +++ b/src/wallet/wallets/WalletError.ts @@ -27,10 +27,15 @@ export class WalletError extends Error { if (typeof err === "string") { throw new WalletError(err, err); } - if (err instanceof Error) { - throw new WalletError(err.message, err); + if (this.isRecord(err)) { + // Takes into account normal error instances and objects with the 'error' key + throw new WalletError(err.message ?? err.error ?? "unknown error", err); } throw new WalletError("unknown error", err); } } + + private static isRecord(value: unknown): value is Record { + return typeof value === "object" && value != null; + } }