summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/wxApi.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-01-09 20:20:09 -0300
committerSebastian <sebasjm@gmail.com>2023-01-09 20:20:09 -0300
commit4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7 (patch)
tree5c16976f99eb973ff62d78ed64107ca01df57b99 /packages/taler-wallet-webextension/src/wxApi.ts
parent8a70edb2f8e235c3462127b0aa4e1b65aa1aee0b (diff)
downloadwallet-core-4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7.tar.gz
wallet-core-4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7.tar.bz2
wallet-core-4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7.zip
fix #7153: more error handling
if handler do not trap error then fail at compile time, all safe handlers push alert on error errors are typed so they render good information
Diffstat (limited to 'packages/taler-wallet-webextension/src/wxApi.ts')
-rw-r--r--packages/taler-wallet-webextension/src/wxApi.ts26
1 files changed, 11 insertions, 15 deletions
diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts
index a41372e37..0393661ac 100644
--- a/packages/taler-wallet-webextension/src/wxApi.ts
+++ b/packages/taler-wallet-webextension/src/wxApi.ts
@@ -93,22 +93,12 @@ export interface BackgroundApiClient {
): Promise<BackgroundOperations[Op]["response"]>;
}
-export class WalletError extends Error {
- public errorDetail: TalerError;
-
- constructor(op: string, e: TalerError) {
- super(`Wallet operation "${op}" failed: ${e.message}`);
- this.errorDetail = e;
- // Object.setPrototypeOf(this, WalletError.prototype);
- }
-}
export class BackgroundError extends Error {
public errorDetail: TalerErrorDetail;
- constructor(op: string, e: TalerErrorDetail) {
- super(`Background operation "${op}" failed: ${e.message}`);
+ constructor(title: string, e: TalerErrorDetail) {
+ super(title);
this.errorDetail = e;
- // Object.setPrototypeOf(this, BackgroundError.prototype);
}
}
@@ -135,13 +125,17 @@ class BackgroundApiClientImpl implements BackgroundApiClient {
if (error instanceof Error) {
throw new BackgroundError(operation, {
code: TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
+ when: new Date().toISOString(),
});
}
throw error;
}
logger.info("got response", response);
if (response.type === "error") {
- throw new BackgroundError(operation, response.error);
+ throw new BackgroundError(
+ `Background operation "${operation}" failed`,
+ response.error,
+ );
}
return response.result as any;
}
@@ -169,8 +163,10 @@ class WalletApiClientImpl implements WalletCoreApiClient {
}
logger.info("got response", response);
if (response.type === "error") {
- const error = TalerError.fromUncheckedDetail(response.error);
- throw new WalletError(operation, error);
+ throw new BackgroundError(
+ `Wallet operation "${operation}" failed`,
+ response.error,
+ );
}
return response.result as any;
}