diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/wxApi.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/wxApi.ts | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts index ce1dac14f..46c9f1b2d 100644 --- a/packages/taler-wallet-webextension/src/wxApi.ts +++ b/packages/taler-wallet-webextension/src/wxApi.ts @@ -24,9 +24,11 @@ import { AbsoluteTime, CoreApiResponse, + DetailsMap, Logger, LogLevel, NotificationType, + TalerError, TalerErrorCode, TalerErrorDetail, WalletDiagnostics, @@ -92,13 +94,19 @@ export interface BackgroundApiClient { ): Promise<BackgroundOperations[Op]["response"]>; } -export class BackgroundError extends Error { - public errorDetail: TalerErrorDetail; +export class BackgroundError<T = any> extends Error { + public errorDetail: TalerErrorDetail & T; - constructor(title: string, e: TalerErrorDetail) { + constructor(title: string, e: TalerErrorDetail & T) { super(title); this.errorDetail = e; } + + hasErrorCode<C extends keyof DetailsMap>( + code: C, + ): this is BackgroundError<DetailsMap[C]> { + return this.errorDetail.code === code; + } } /** |