diff options
author | Sebastian <sebasjm@gmail.com> | 2023-12-13 15:15:37 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-12-13 15:15:37 -0300 |
commit | cd1201ef6c737b007adf1c3c572b41d793f2296b (patch) | |
tree | 8fc1972aa419b252d69f27c44f86a1cbde1cb604 /packages/web-util/src | |
parent | 145c36e9ba549b7ccc72a29eaf102879011060a4 (diff) | |
download | wallet-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.ts | 32 | ||||
-rw-r--r-- | packages/web-util/src/utils/http-impl.sw.ts | 28 |
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( |