diff options
author | Florian Dold <florian@dold.me> | 2022-09-19 12:13:31 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-09-19 12:13:31 +0200 |
commit | fd752f3171a76129d2f615535b90c6bebb88d842 (patch) | |
tree | 93b49a6e5636cd7eeac2655ec0905aeb0b5b241c /packages/taler-wallet-core/src/errors.ts | |
parent | 548cecca212bb40d56a868736d998c484d721f65 (diff) | |
download | wallet-core-fd752f3171a76129d2f615535b90c6bebb88d842.tar.xz |
wallet-core: hide transient pay errors
Diffstat (limited to 'packages/taler-wallet-core/src/errors.ts')
-rw-r--r-- | packages/taler-wallet-core/src/errors.ts | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/packages/taler-wallet-core/src/errors.ts b/packages/taler-wallet-core/src/errors.ts index d56e936c0..62bde667d 100644 --- a/packages/taler-wallet-core/src/errors.ts +++ b/packages/taler-wallet-core/src/errors.ts @@ -70,6 +70,9 @@ export interface DetailsMap { [TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE]: {}; [TalerErrorCode.WALLET_CORE_NOT_AVAILABLE]: {}; [TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR]: {}; + [TalerErrorCode.WALLET_PAY_MERCHANT_SERVER_ERROR]: { + requestError: TalerErrorDetail; + }; } type ErrBody<Y> = Y extends keyof DetailsMap ? DetailsMap[Y] : never; @@ -79,7 +82,9 @@ export function makeErrorDetail<C extends TalerErrorCode>( detail: ErrBody<C>, hint?: string, ): TalerErrorDetail { - // FIXME: include default hint? + if (!hint && !(detail as any).hint) { + hint = getDefaultHint(code); + } return { code, hint, ...detail }; } @@ -99,6 +104,15 @@ export function summarizeTalerErrorDetail(ed: TalerErrorDetail): string { return `Error (${ed.code}/${errName})`; } +function getDefaultHint(code: number): string { + const errName = TalerErrorCode[code]; + if (errName) { + return `Error (${errName})`; + } else { + return `Error (<unknown>)`; + } +} + export class TalerError<T = any> extends Error { errorDetail: TalerErrorDetail & T; private constructor(d: TalerErrorDetail & T) { @@ -113,12 +127,7 @@ export class TalerError<T = any> extends Error { hint?: string, ): TalerError { if (!hint) { - const errName = TalerErrorCode[code]; - if (errName) { - hint = `Error (${errName})`; - } else { - hint = `Error (<unknown>)`; - } + hint = getDefaultHint(code); } return new TalerError<unknown>({ code, hint, ...detail }); } |