diff options
author | Sebastian <sebasjm@gmail.com> | 2024-03-04 11:52:36 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-03-04 11:52:36 -0300 |
commit | c58349ebaa173881a4201e83e928325707758eb8 (patch) | |
tree | a5cf60762675072f7f2b6edbe1d12568aebc7e74 /packages/taler-wallet-webextension/src/wxApi.ts | |
parent | 97d4a6445ad86ffad842fd763e0ac8053b971e69 (diff) | |
download | wallet-core-c58349ebaa173881a4201e83e928325707758eb8.tar.xz |
fix #8371
Diffstat (limited to 'packages/taler-wallet-webextension/src/wxApi.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/wxApi.ts | 25 |
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, |