Skip to content

Commit

Permalink
fix: update wrap to handle more wallet errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronCQL committed Jul 3, 2024
1 parent 09ccce2 commit a41a462
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/wallet/wallets/WalletError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> {
return typeof value === "object" && value != null;
}
}

0 comments on commit a41a462

Please sign in to comment.