diff options
author | Florian Dold <florian@dold.me> | 2022-03-22 21:16:38 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-03-22 21:16:38 +0100 |
commit | 5d23eb36354d07508a015531f298b3e261bbafce (patch) | |
tree | fae0d2599c94d88c9264bb63a301adb1706824c1 /packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts | |
parent | f8d12f7b0d4af1b1769b89e80c87f9c169678564 (diff) | |
download | wallet-core-5d23eb36354d07508a015531f298b3e261bbafce.tar.xz |
wallet: improve error handling and error codes
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts index 6efa1d181..8d31de94f 100644 --- a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts +++ b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts @@ -13,28 +13,32 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { NotificationType, TalerErrorDetails } from "@gnu-taler/taler-util"; +import { + NotificationType, + TalerErrorCode, + TalerErrorDetail, +} from "@gnu-taler/taler-util"; +import { TalerError } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; import * as wxApi from "../wxApi"; -import { OperationFailedError } from "@gnu-taler/taler-wallet-core"; interface HookOk<T> { hasError: false; response: T; } -export type HookError = HookGenericError | HookOperationalError +export type HookError = HookGenericError | HookOperationalError; export interface HookGenericError { hasError: true; - operational: false, + operational: false; message: string; } export interface HookOperationalError { hasError: true; - operational: true, - details: TalerErrorDetails; + operational: true; + details: TalerErrorDetail; } export type HookResponse<T> = HookOk<T> | HookError | undefined; @@ -51,10 +55,18 @@ export function useAsyncAsHook<T>( const response = await fn(); setHookResponse({ hasError: false, response }); } catch (e) { - if (e instanceof OperationFailedError) { - setHookResponse({ hasError: true, operational: true, details: e.operationError }); + if (e instanceof TalerError) { + setHookResponse({ + hasError: true, + operational: true, + details: e.errorDetail, + }); } else if (e instanceof Error) { - setHookResponse({ hasError: true, operational: false, message: e.message }); + setHookResponse({ + hasError: true, + operational: false, + message: e.message, + }); } } } |