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.sw.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'packages/web-util/src/utils/http-impl.sw.ts') 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 { - 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( -- cgit v1.2.3