gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: better error handling


From: gnunet
Subject: [taler-wallet-core] branch master updated: better error handling
Date: Wed, 15 Mar 2023 13:54:37 +0100

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new ae4d4647e better error handling
ae4d4647e is described below

commit ae4d4647e988a6eb8e9fd87af3385371ba56ab43
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Wed Mar 15 09:54:31 2023 -0300

    better error handling
---
 .../src/components/exception/login.tsx                  |  4 ++--
 packages/merchant-backoffice-ui/src/hooks/backend.ts    | 17 +++++++++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/packages/merchant-backoffice-ui/src/components/exception/login.tsx 
b/packages/merchant-backoffice-ui/src/components/exception/login.tsx
index 435ff1d6a..52b5b2a24 100644
--- a/packages/merchant-backoffice-ui/src/components/exception/login.tsx
+++ b/packages/merchant-backoffice-ui/src/components/exception/login.tsx
@@ -141,8 +141,8 @@ export function LoginModal({ onConfirm, withMessage }: 
Props): VNode {
               class="button is-info"
               onClick={async () => {
                 const secretToken = normalizeToken(token);
-                const isOk = await testLogin(url, secretToken);
-                if (isOk) {
+                const { valid, cause } = await testLogin(url, secretToken);
+                if (valid) {
                   onConfirm(url, secretToken);
                 } else {
                   onConfirm(url);
diff --git a/packages/merchant-backoffice-ui/src/hooks/backend.ts 
b/packages/merchant-backoffice-ui/src/hooks/backend.ts
index 93e95934e..3ab99b402 100644
--- a/packages/merchant-backoffice-ui/src/hooks/backend.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/backend.ts
@@ -25,8 +25,10 @@ import { useBackendContext } from "../context/backend.js";
 import { useCallback, useEffect, useState } from "preact/hooks";
 import { useInstanceContext } from "../context/instance.js";
 import {
+  ErrorType,
   HttpResponse,
   HttpResponseOk,
+  RequestError,
   RequestOptions,
 } from "@gnu-taler/web-util/lib/index.browser";
 import { useApiContext } from "@gnu-taler/web-util/lib/index.browser";
@@ -146,14 +148,21 @@ export function useCredentialsChecker() {
   return async function testLogin(
     instance: string,
     token: string,
-  ): Promise<boolean> {
+  ): Promise<{
+    valid: boolean;
+    cause?: ErrorType;
+  }> {
     try {
       const response = await request(instance, `/private/`, {
         token,
       });
-      return true;
-    } catch (e) {
-      return false;
+      return { valid: true };
+    } catch (error) {
+      if (error instanceof RequestError) {
+        return { valid: false, cause: error.cause.type };
+      }
+
+      return { valid: false, cause: ErrorType.UNEXPECTED };
     }
   };
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]