From cd1201ef6c737b007adf1c3c572b41d793f2296b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 13 Dec 2023 15:15:37 -0300 Subject: fix withdraw-exchange redirect when there is not amount --- packages/web-util/src/utils/http-impl.browser.ts | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'packages/web-util/src/utils/http-impl.browser.ts') 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 => { - 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( -- cgit v1.2.3