aboutsummaryrefslogtreecommitdiff
path: root/packages/web-util/src
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-12-13 15:15:37 -0300
committerSebastian <sebasjm@gmail.com>2023-12-13 15:15:37 -0300
commitcd1201ef6c737b007adf1c3c572b41d793f2296b (patch)
tree8fc1972aa419b252d69f27c44f86a1cbde1cb604 /packages/web-util/src
parent145c36e9ba549b7ccc72a29eaf102879011060a4 (diff)
downloadwallet-core-cd1201ef6c737b007adf1c3c572b41d793f2296b.tar.xz
fix withdraw-exchange redirect when there is not amount
Diffstat (limited to 'packages/web-util/src')
-rw-r--r--packages/web-util/src/utils/http-impl.browser.ts32
-rw-r--r--packages/web-util/src/utils/http-impl.sw.ts28
2 files changed, 32 insertions, 28 deletions
diff --git a/packages/web-util/src/utils/http-impl.browser.ts b/packages/web-util/src/utils/http-impl.browser.ts
index db789a536..974a7d1b8 100644
--- a/packages/web-util/src/utils/http-impl.browser.ts
+++ b/packages/web-util/src/utils/http-impl.browser.ts
@@ -140,22 +140,24 @@ export class BrowserHttpLib implements HttpRequestLibrary {
const td = new TextDecoder();
return td.decode(myRequest.response);
};
+ let responseJson: unknown = undefined;
const makeJson = async (): Promise<any> => {
- let responseJson;
- try {
- const td = new TextDecoder();
- const responseString = td.decode(myRequest.response);
- responseJson = JSON.parse(responseString);
- } catch (e) {
- throw TalerError.fromDetail(
- TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
- {
- requestUrl,
- requestMethod,
- httpStatusCode: myRequest.status,
- },
- "Invalid JSON from HTTP response",
- );
+ if (responseJson === undefined) {
+ try {
+ const td = new TextDecoder();
+ const responseString = td.decode(myRequest.response);
+ responseJson = JSON.parse(responseString);
+ } catch (e) {
+ throw TalerError.fromDetail(
+ TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
+ {
+ requestUrl,
+ requestMethod,
+ httpStatusCode: myRequest.status,
+ },
+ "Invalid JSON from HTTP response",
+ );
+ }
}
if (responseJson === null || typeof responseJson !== "object") {
throw TalerError.fromDetail(
diff --git a/packages/web-util/src/utils/http-impl.sw.ts b/packages/web-util/src/utils/http-impl.sw.ts
index aab88021f..295681b53 100644
--- a/packages/web-util/src/utils/http-impl.sw.ts
+++ b/packages/web-util/src/utils/http-impl.sw.ts
@@ -176,20 +176,22 @@ function makeJsonHandler(
requestUrl: string,
requestMethod: string,
) {
+ let responseJson: unknown = undefined;
return async function getJsonFromResponse(): Promise<any> {
- let responseJson;
- try {
- responseJson = await response.json();
- } catch (e) {
- throw TalerError.fromDetail(
- TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
- {
- requestUrl,
- requestMethod,
- httpStatusCode: response.status,
- },
- "Invalid JSON from HTTP response",
- );
+ if (responseJson === undefined) {
+ try {
+ responseJson = await response.json();
+ } catch (e) {
+ throw TalerError.fromDetail(
+ TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
+ {
+ requestUrl,
+ requestMethod,
+ httpStatusCode: response.status,
+ },
+ "Invalid JSON from HTTP response",
+ );
+ }
}
if (responseJson === null || typeof responseJson !== "object") {
throw TalerError.fromDetail(