gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (5cab30306 -> 6b61e565b)


From: gnunet
Subject: [taler-wallet-core] branch master updated (5cab30306 -> 6b61e565b)
Date: Sun, 21 Apr 2024 09:54:32 +0200

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

nora-grothoff pushed a change to branch master
in repository wallet-core.

    from 5cab30306 use git short hashes
     new 9b1d1feac handle error
     new 8841c30a5 use new Error (standard, as error is a class)
     new 6b61e565b check for non-2xx, cache any 2xx responses that pass minimal 
validation

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/hooks/use-anastasis-reducer.ts             |  6 +--
 packages/anastasis-webui/src/index.ts              |  2 +-
 .../src/pages/home/AddingProviderScreen/index.ts   | 61 +++++++++++++++++-----
 3 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts 
b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
index fc8c4cf6c..fcc380775 100644
--- a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
+++ b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
@@ -303,7 +303,7 @@ export function useAnastasisReducer(): AnastasisReducerApi {
           },
         });
       } catch (e) {
-        throw Error("could not restore the state");
+        throw new Error("could not restore the state");
       }
     },
     async discoverStart(): Promise<void> {
@@ -399,7 +399,7 @@ export function useAnastasisReducer(): AnastasisReducerApi {
 }
 
 class ReducerTxImpl implements ReducerTransactionHandle {
-  constructor(public transactionState: ReducerState) { }
+  constructor(public transactionState: ReducerState) {}
   async transition(action: string, args: any): Promise<ReducerState> {
     let s: ReducerState;
     if (remoteReducer) {
@@ -410,7 +410,7 @@ class ReducerTxImpl implements ReducerTransactionHandle {
     this.transactionState = s;
     // Abort transaction as soon as we transition into an error state.
     if (this.transactionState.reducer_type === "error") {
-      throw Error("transition resulted in error");
+      throw new Error("transition resulted in error");
     }
     return this.transactionState;
   }
diff --git a/packages/anastasis-webui/src/index.ts 
b/packages/anastasis-webui/src/index.ts
index d7b2164ab..f614e4f54 100644
--- a/packages/anastasis-webui/src/index.ts
+++ b/packages/anastasis-webui/src/index.ts
@@ -22,7 +22,7 @@ function main(): void {
   try {
     const container = document.getElementById("container");
     if (!container) {
-      throw Error("container not found, can't mount page contents");
+      throw new Error("container not found, can't mount page contents");
     }
     render(h(App, {}), container);
   } catch (e) {
diff --git 
a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts 
b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts
index 0ab275f54..365d2e8e7 100644
--- a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts
+++ b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/index.ts
@@ -24,7 +24,7 @@ import { WithoutProviderType, WithProviderType } from 
"./views.js";
 export type AuthProvByStatusMap = Record<
   AuthenticationProviderStatus["status"],
   (AuthenticationProviderStatus & { url: string })[]
->
+>;
 
 export type State = NoReducer | InvalidState | WithType | WithoutType;
 
@@ -63,21 +63,56 @@ const map: StateViewMap<State> = {
   "without-type": WithoutProviderType,
 };
 
-export default compose("AddingProviderScreen", useComponentState, map)
-
+export default compose("AddingProviderScreen", useComponentState, map);
 
+const providerResponseCache = new Map<string, any>(); // `any` is the return 
type of res.json()
 export async function testProvider(
   url: string,
   expectedMethodType?: string,
 ): Promise<void> {
   try {
-    const response = await fetch(new URL("config", url).href);
-    const json = await response.json().catch((d) => ({}));
+    // TODO: look into using core.getProviderInfo :)
+    const providerHasUrl = providerResponseCache.has(url);
+    const json = providerHasUrl
+      ? providerResponseCache.get(url)
+      : await fetch(new URL("config", url).href)
+          .catch((error) => {
+            console.error("Provider HTTP Error:", error);
+            throw new Error(
+              "Encountered a fatal error whilst testing the provider: " + url,
+            );
+          })
+          .then(async (response) => {
+            if (!response.ok)
+              throw new Error(
+                `The server ${response.url} responded with a non-2xx 
response.`,
+              );
+            try {
+              return await response.json();
+            } catch (error) {
+              console.error("Provider Parsing Error:", error);
+              throw new Error(
+                "Encountered a fatal error whilst testing the provider: " + 
url,
+              );
+            }
+          });
+    if (typeof json !== "object")
+      throw new Error(
+        "Encountered a fatal error whilst testing the provider: " +
+          url +
+          "\nError: Did not get an object after decoding.",
+      );
+    if (!("name" in json) || json.name !== "anastasis") {
+      throw new Error(
+        "The provider does not appear to be an Anastasis provider. Please 
check the provider's URL.",
+      );
+    }
     if (!("methods" in json) || !Array.isArray(json.methods)) {
-      throw Error(
-        "This provider doesn't have authentication method. Check the provider 
URL",
+      throw new Error(
+        "This provider doesn't have authentication method. Please check the 
provider's URL and ensure it is properly configured.",
       );
     }
+    if (!providerHasUrl) providerResponseCache.set(url, json);
     if (!expectedMethodType) {
       return;
     }
@@ -86,7 +121,7 @@ export async function testProvider(
       found = json.methods[i].type === expectedMethodType;
     }
     if (!found) {
-      throw Error(
+      throw new Error(
         `This provider does not support authentication method 
${expectedMethodType}`,
       );
     }
@@ -95,10 +130,12 @@ export async function testProvider(
     console.log("ERROR testProvider", e);
     const error =
       e instanceof Error
-        ? Error(
-          `There was an error testing this provider, try another one. 
${e.message}`,
-        )
-        : Error(`There was an error testing this provider, try another one.`);
+        ? new Error(
+            `There was an error testing this provider, try another one. 
${e.message}`,
+          )
+        : new Error(
+            `There was an error testing this provider, try another one.`,
+          );
     throw error;
   }
 }

-- 
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]