taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 467ab67cc90e3c3dbd2e3c4d9e686865e1f747ee
parent 221f3e6b2da1f491fc15a88f324fb155227efca6
Author: Florian Dold <dold@taler.net>
Date:   Tue, 21 Jul 2026 10:56:44 +0200

util: tolerate a JSON null body when reading an error response

JSON.parse("null") succeeds, so reading .code off the result threw a
TypeError that escaped uncaught, without the request URL, method or status.

Diffstat:
Mpackages/taler-util/src/http-common.ts | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts @@ -241,7 +241,7 @@ export async function readTalerErrorResponse( ); } - const talerErrorCode = errJson.code; + const talerErrorCode = errJson?.code; if (typeof talerErrorCode !== "number") { logger.warn( `malformed error response (status ${httpResponse.status}): ${j2s( @@ -281,7 +281,7 @@ export async function readUnexpectedResponseDetails( "Couldn't parse JSON format from error response", ); } - const talerErrorCode = errJson.code; + const talerErrorCode = errJson?.code; if (typeof talerErrorCode !== "number") { return makeErrorDetail( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, @@ -469,7 +469,7 @@ export async function readSuccessResponseTextOrErrorCode<T>( ); } - const talerErrorCode = errJson.code; + const talerErrorCode = errJson?.code; if (typeof talerErrorCode !== "number") { throw TalerError.fromDetail( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, @@ -515,7 +515,7 @@ export async function checkSuccessResponseOrThrow( ); } - const talerErrorCode = errJson.code; + const talerErrorCode = errJson?.code; if (typeof talerErrorCode !== "number") { throw TalerError.fromDetail( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,