From 2a417881bb5c67cf889d54932025badf5a85a9e0 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 20 Jan 2022 13:13:53 -0300 Subject: fix permission api, grouping all cta into same path --- .../src/hooks/useAsyncAsHook.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts') diff --git a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts index e9f03d0fa..6efa1d181 100644 --- a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts +++ b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts @@ -13,20 +13,30 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see */ -import { NotificationType } from "@gnu-taler/taler-util"; +import { NotificationType, TalerErrorDetails } from "@gnu-taler/taler-util"; import { useEffect, useState } from "preact/hooks"; import * as wxApi from "../wxApi"; +import { OperationFailedError } from "@gnu-taler/taler-wallet-core"; interface HookOk { hasError: false; response: T; } -interface HookError { +export type HookError = HookGenericError | HookOperationalError + +export interface HookGenericError { hasError: true; + operational: false, message: string; } +export interface HookOperationalError { + hasError: true; + operational: true, + details: TalerErrorDetails; +} + export type HookResponse = HookOk | HookError | undefined; //"withdraw-group-finished" @@ -41,8 +51,10 @@ export function useAsyncAsHook( const response = await fn(); setHookResponse({ hasError: false, response }); } catch (e) { - if (e instanceof Error) { - setHookResponse({ hasError: true, message: e.message }); + if (e instanceof OperationFailedError) { + setHookResponse({ hasError: true, operational: true, details: e.operationError }); + } else if (e instanceof Error) { + setHookResponse({ hasError: true, operational: false, message: e.message }); } } } -- cgit v1.2.3