diff options
Diffstat (limited to 'packages/taler-util/src/errors.ts')
-rw-r--r-- | packages/taler-util/src/errors.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/packages/taler-util/src/errors.ts b/packages/taler-util/src/errors.ts index 11f01a3fe..9378d25e8 100644 --- a/packages/taler-util/src/errors.ts +++ b/packages/taler-util/src/errors.ts @@ -25,6 +25,7 @@ */ import { AbsoluteTime, + CancellationToken, PaymentInsufficientBalanceDetails, TalerErrorCode, TalerErrorDetail, @@ -277,6 +278,10 @@ export class TalerError<T = any> extends Error { } } +export function safeStringifyException(e: any): string { + return JSON.stringify(getErrorDetailFromException(e), undefined, 2); +} + /** * Convert an exception (or anything that was thrown) into * a TalerErrorDetail object. @@ -285,6 +290,13 @@ export function getErrorDetailFromException(e: any): TalerErrorDetail { if (e instanceof TalerError) { return e.errorDetail; } + if (e instanceof CancellationToken.CancellationError) { + const err = makeErrorDetail( + TalerErrorCode.WALLET_CORE_REQUEST_CANCELLED, + {}, + ); + return err; + } if (e instanceof Error) { const err = makeErrorDetail( TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION, |