diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-09-06 18:32:05 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-09-06 18:32:05 +0530 |
commit | 87749371dd6a8ca29d812d6f58cffa5feb6ec41c (patch) | |
tree | c7c394648d4471b3a77d195b90e3b42e3b2a6ac3 /packages/taler-wallet-core | |
parent | 92873710f1e94a4b04a6785326f4dd27fb759237 (diff) | |
download | wallet-core-87749371dd6a8ca29d812d6f58cffa5feb6ec41c.tar.xz |
convert axios error to taler error
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/headless/NodeHttpLib.ts | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/packages/taler-wallet-core/src/headless/NodeHttpLib.ts b/packages/taler-wallet-core/src/headless/NodeHttpLib.ts index 4fefb5aef..ed4e0e1eb 100644 --- a/packages/taler-wallet-core/src/headless/NodeHttpLib.ts +++ b/packages/taler-wallet-core/src/headless/NodeHttpLib.ts @@ -26,7 +26,7 @@ import { HttpResponse, } from "../util/http"; import { RequestThrottler } from "../util/RequestThrottler"; -import Axios from "axios"; +import Axios, { AxiosResponse } from "axios"; import { OperationFailedError, makeErrorDetails } from "../operations/errors"; import { TalerErrorCode } from "../TalerErrorCode"; import { URL } from "../util/url"; @@ -70,16 +70,28 @@ export class NodeHttpLib implements HttpRequestLibrary { if (typeof opt?.timeout?.d_ms === "number") { timeout = opt.timeout.d_ms; } - const resp = await Axios({ - method, - url: url, - responseType: "text", - headers: opt?.headers, - validateStatus: () => true, - transformResponse: (x) => x, - data: body, - timeout, - }); + let resp: AxiosResponse; + try { + resp = await Axios({ + method, + url: url, + responseType: "text", + headers: opt?.headers, + validateStatus: () => true, + transformResponse: (x) => x, + data: body, + timeout, + }); + } catch (e) { + throw OperationFailedError.fromCode( + TalerErrorCode.WALLET_NETWORK_ERROR, + `${e.message}`, + { + requestUrl: url, + requestMethod: method, + }, + ); + } const respText = resp.data; if (typeof respText !== "string") { |