gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (8c8aad4c2 -> 46607dc26)


From: gnunet
Subject: [taler-wallet-core] branch master updated (8c8aad4c2 -> 46607dc26)
Date: Tue, 20 Dec 2022 17:44:49 +0100

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

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

    from 8c8aad4c2 fix #7524: do not break if the account is in an invalid state
     new 15d76cf77 add WALLET_HTTP_REQUEST_GENERIC_TIMEOUT to error map
     new 46607dc26 handler request timeout

The 2 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:
 packages/taler-wallet-core/src/errors.ts           |  1 +
 .../src/serviceWorkerHttpLib.ts                    | 68 +++++++++++++++-------
 2 files changed, 49 insertions(+), 20 deletions(-)

diff --git a/packages/taler-wallet-core/src/errors.ts 
b/packages/taler-wallet-core/src/errors.ts
index 3480fed3c..99a7fb535 100644
--- a/packages/taler-wallet-core/src/errors.ts
+++ b/packages/taler-wallet-core/src/errors.ts
@@ -64,6 +64,7 @@ export interface DetailsMap {
   [TalerErrorCode.WALLET_BANK_INTEGRATION_PROTOCOL_VERSION_INCOMPATIBLE]: {};
   [TalerErrorCode.WALLET_CORE_API_OPERATION_UNKNOWN]: {};
   [TalerErrorCode.WALLET_HTTP_REQUEST_THROTTLED]: {};
+  [TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT]: {};
   [TalerErrorCode.WALLET_NETWORK_ERROR]: {};
   [TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE]: {};
   [TalerErrorCode.WALLET_EXCHANGE_COIN_SIGNATURE_INVALID]: {};
diff --git a/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts 
b/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts
index 74c7f161d..c9327b8e6 100644
--- a/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts
+++ b/packages/taler-wallet-webextension/src/serviceWorkerHttpLib.ts
@@ -17,7 +17,11 @@
 /**
  * Imports.
  */
-import { RequestThrottler, TalerErrorCode } from "@gnu-taler/taler-util";
+import {
+  Logger,
+  RequestThrottler,
+  TalerErrorCode,
+} from "@gnu-taler/taler-util";
 import {
   Headers,
   HttpRequestLibrary,
@@ -41,6 +45,7 @@ export class ServiceWorkerHttpLib implements 
HttpRequestLibrary {
     const requestMethod = options?.method ?? "GET";
     const requestBody = options?.body;
     const requestHeader = options?.headers;
+    const requestTimeout = options?.timeout ?? { d_ms: 2 * 1000 };
 
     if (this.throttlingEnabled && this.throttle.applyThrottle(requestUrl)) {
       const parsedUrl = new URL(requestUrl);
@@ -70,26 +75,49 @@ export class ServiceWorkerHttpLib implements 
HttpRequestLibrary {
       }
     }
 
-    const response = await fetch(requestUrl, {
-      headers: requestHeader,
-      body: myBody,
-      method: requestMethod,
-      // timeout: options?.timeout
-    });
+    const controller = new AbortController();
+    let timeoutId: any | undefined;
+    if (requestTimeout.d_ms !== "forever") {
+      timeoutId = setTimeout(() => {
+        controller.abort(TalerErrorCode.WALLET_HTTP_REQUEST_GENERIC_TIMEOUT);
+      }, requestTimeout.d_ms);
+    }
 
-    const headerMap = new Headers();
-    response.headers.forEach((value, key) => {
-      headerMap.set(key, value);
-    });
-    return {
-      headers: headerMap,
-      status: response.status,
-      requestMethod,
-      requestUrl,
-      json: makeJsonHandler(response, requestUrl),
-      text: makeTextHandler(response, requestUrl),
-      bytes: async () => (await response.blob()).arrayBuffer(),
-    };
+    try {
+      const response = await fetch(requestUrl, {
+        headers: requestHeader,
+        body: myBody,
+        method: requestMethod,
+        signal: controller.signal,
+      });
+
+      if (timeoutId) {
+        clearTimeout(timeoutId);
+      }
+
+      const headerMap = new Headers();
+      response.headers.forEach((value, key) => {
+        headerMap.set(key, value);
+      });
+      return {
+        headers: headerMap,
+        status: response.status,
+        requestMethod,
+        requestUrl,
+        json: makeJsonHandler(response, requestUrl),
+        text: makeTextHandler(response, requestUrl),
+        bytes: async () => (await response.blob()).arrayBuffer(),
+      };
+    } catch (e) {
+      if (controller.signal) {
+        throw TalerError.fromDetail(
+          controller.signal.reason,
+          {},
+          `request to ${requestUrl} timed out`,
+        );
+      }
+      throw e;
+    }
   }
 
   get(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> {

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