aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/errors.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-05-31 15:08:31 +0200
committerFlorian Dold <florian@dold.me>2022-05-31 15:08:31 +0200
commit2e6f3b356971f3a56ff78db0ea6fa75ce0ab85b2 (patch)
treee2f9f2cf21e3f1ead7707c1d9db03df3b3deaada /packages/taler-wallet-core/src/errors.ts
parent182439cfdae6fe8307223a53c29c9fd3939fb4ba (diff)
downloadwallet-core-2e6f3b356971f3a56ff78db0ea6fa75ce0ab85b2.tar.xz
-error reporting, code formatting
Diffstat (limited to 'packages/taler-wallet-core/src/errors.ts')
-rw-r--r--packages/taler-wallet-core/src/errors.ts14
1 files changed, 13 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/errors.ts b/packages/taler-wallet-core/src/errors.ts
index eda5444bf..56017cc00 100644
--- a/packages/taler-wallet-core/src/errors.ts
+++ b/packages/taler-wallet-core/src/errors.ts
@@ -94,6 +94,11 @@ export function makePendingOperationFailedError(
});
}
+export function summarizeTalerErrorDetail(ed: TalerErrorDetail): string {
+ const errName = TalerErrorCode[ed.code] ?? "<unknown>";
+ return `Error (${ed.code}/${errName})`;
+}
+
export class TalerError<T = any> extends Error {
errorDetail: TalerErrorDetail & T;
private constructor(d: TalerErrorDetail & T) {
@@ -107,7 +112,14 @@ export class TalerError<T = any> extends Error {
detail: ErrBody<C>,
hint?: string,
): TalerError {
- // FIXME: include default hint?
+ if (!hint) {
+ const errName = TalerErrorCode[code];
+ if (errName) {
+ hint = `Error (${errName})`;
+ } else {
+ hint = `Error (<unknown>)`;
+ }
+ }
return new TalerError<unknown>({ code, hint, ...detail });
}