taler-typescript-core

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

commit 36951014eea03f0f9da872b62a8a48e9cc55d87d
parent 7b78488339385e694c1303337350d2573107d3c5
Author: Florian Dold <florian@dold.me>
Date:   Wed,  7 Jan 2026 19:15:19 +0100

util: parse media type from content type in error handling

Instead of requiring an exact match for "application/json", we now also
accept Content-Type header values like "application/json;
charset=UTF-8".

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

diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts @@ -143,7 +143,11 @@ export async function readTalerErrorResponse( httpResponse: HttpResponse, ): Promise<TalerErrorDetail> { const contentType = httpResponse.headers.get("content-type"); - if (contentType !== "application/json") { + let mediaType: string | undefined = undefined; + if (contentType) { + mediaType = contentType.split(";")[0].trim().toLowerCase(); + } + if (mediaType !== "application/json") { throw TalerError.fromDetail( TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, { @@ -151,7 +155,7 @@ export async function readTalerErrorResponse( requestMethod: httpResponse.requestMethod, httpStatusCode: httpResponse.status, response: await httpResponse.text(), - contentType: contentType || "<null>", + contentType: mediaType || "<null>", }, "Error response did not even contain JSON. The request URL might be wrong or the service might be unavailable.", );