From 421e613f92b80c81c856d6b074aa160e80e38e3d Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Aug 2020 16:27:20 +0530 Subject: throttling diagnostics and request timeouts --- packages/taler-wallet-core/src/headless/NodeHttpLib.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'packages/taler-wallet-core/src/headless/NodeHttpLib.ts') diff --git a/packages/taler-wallet-core/src/headless/NodeHttpLib.ts b/packages/taler-wallet-core/src/headless/NodeHttpLib.ts index 59730ab30..85f37cfa3 100644 --- a/packages/taler-wallet-core/src/headless/NodeHttpLib.ts +++ b/packages/taler-wallet-core/src/headless/NodeHttpLib.ts @@ -29,6 +29,7 @@ import { RequestThrottler } from "../util/RequestThrottler"; import Axios from "axios"; import { OperationFailedError, makeErrorDetails } from "../operations/errors"; import { TalerErrorCode } from "../TalerErrorCode"; +import { URL } from "../util/url"; /** * Implementation of the HTTP request library interface for node. @@ -50,8 +51,20 @@ export class NodeHttpLib implements HttpRequestLibrary { body: any, opt?: HttpRequestOptions, ): Promise { + const parsedUrl = new URL(url); if (this.throttlingEnabled && this.throttle.applyThrottle(url)) { - throw Error("request throttled"); + throw OperationFailedError.fromCode( + TalerErrorCode.WALLET_HTTP_REQUEST_THROTTLED, + `request to origin ${parsedUrl.origin} was throttled`, + { + requestMethod: method, + requestUrl: url, + throttleStats: this.throttle.getThrottleStats(url), + }); + } + let timeout: number | undefined; + if (typeof opt?.timeout?.d_ms === "number") { + timeout = opt.timeout.d_ms; } const resp = await Axios({ method, @@ -61,6 +74,7 @@ export class NodeHttpLib implements HttpRequestLibrary { validateStatus: () => true, transformResponse: (x) => x, data: body, + timeout, }); const respText = resp.data; -- cgit v1.2.3