diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-08-20 16:27:20 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-08-20 16:27:20 +0530 |
commit | 421e613f92b80c81c856d6b074aa160e80e38e3d (patch) | |
tree | 7284e8b856986de3ee4ca1362fa9b52ce1e22de1 /packages/taler-wallet-core/src/headless | |
parent | ddf9171c5becb3bb1aebdd3e1a298644f62ed090 (diff) | |
download | wallet-core-421e613f92b80c81c856d6b074aa160e80e38e3d.tar.xz |
throttling diagnostics and request timeouts
Diffstat (limited to 'packages/taler-wallet-core/src/headless')
-rw-r--r-- | packages/taler-wallet-core/src/headless/NodeHttpLib.ts | 16 |
1 files changed, 15 insertions, 1 deletions
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<HttpResponse> { + 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; |