summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/wxApi.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-webextension/src/wxApi.ts')
-rw-r--r--packages/taler-wallet-webextension/src/wxApi.ts25
1 files changed, 17 insertions, 8 deletions
diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts
index c53b15ef0..90522f662 100644
--- a/packages/taler-wallet-webextension/src/wxApi.ts
+++ b/packages/taler-wallet-webextension/src/wxApi.ts
@@ -97,11 +97,13 @@ export interface BackgroundApiClient {
}
export class BackgroundError<T = any> extends Error {
- public errorDetail: TalerErrorDetail & T;
+ public readonly errorDetail: TalerErrorDetail & T;
+ public readonly cause: Error;
- constructor(title: string, e: TalerErrorDetail & T) {
+ constructor(title: string, e: TalerErrorDetail & T, cause: Error) {
super(title);
this.errorDetail = e;
+ this.cause = cause;
}
hasErrorCode<C extends keyof DetailsMap>(
@@ -134,7 +136,7 @@ class BackgroundApiClientImpl implements BackgroundApiClient {
throw new BackgroundError(operation, {
code: TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
when: AbsoluteTime.now(),
- });
+ }, error);
}
throw error;
}
@@ -142,6 +144,7 @@ class BackgroundApiClientImpl implements BackgroundApiClient {
throw new BackgroundError(
`Background operation "${operation}" failed`,
response.error,
+ TalerError.fromUncheckedDetail(response.error),
);
}
logger.trace("response", response);
@@ -165,14 +168,20 @@ class WalletApiClientImpl implements WalletCoreApiClient {
payload,
};
response = await platform.sendMessageToBackground(message);
- } catch (e) {
- logger.error("Error calling backend", e);
- throw new Error(`Error contacting backend: ${e}`);
+ } catch (error) {
+ if (error instanceof Error) {
+ throw new BackgroundError(operation, {
+ code: TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
+ when: AbsoluteTime.now(),
+ }, error);
+ }
+ throw error;
}
if (response.type === "error") {
throw new BackgroundError(
`Wallet operation "${operation}" failed`,
response.error,
+ TalerError.fromUncheckedDetail(response.error)
);
}
logger.trace("got response", response);
@@ -182,7 +191,7 @@ class WalletApiClientImpl implements WalletCoreApiClient {
function onUpdateNotification(
messageTypes: Array<NotificationType>,
- doCallback: undefined | ((n:WalletNotification) => void),
+ doCallback: undefined | ((n: WalletNotification) => void),
): () => void {
//if no callback, then ignore
if (!doCallback)
@@ -207,7 +216,7 @@ export type WxApiType = {
};
};
-function trigger(w:ExtensionNotification) {
+function trigger(w: ExtensionNotification) {
platform.triggerWalletEvent({
type: "web-extension",
notification: w,