taler-typescript-core

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

commit 342df60abe6d8b8b0c51e79cf13c7edcca58d9f9
parent 39897b0c24eec28e86235351b451ca8f9e26e8c7
Author: Florian Dold <florian@dold.me>
Date:   Tue, 21 Nov 2023 11:51:14 +0100

improve error message when error response doesn't even contain JSON

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

diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts @@ -141,9 +141,24 @@ type ResponseOrError<T> = | { isError: false; response: T } | { isError: true; talerErrorResponse: TalerErrorResponse }; +/** + * Read Taler error details from an HTTP response. + */ export async function readTalerErrorResponse( httpResponse: HttpResponse, ): Promise<TalerErrorDetail> { + const contentType = httpResponse.headers.get("content-type"); + if (contentType !== "application/json") { + throw TalerError.fromDetail( + TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, + { + requestUrl: httpResponse.requestUrl, + requestMethod: httpResponse.requestMethod, + httpStatusCode: httpResponse.status, + }, + "Error response did not even contain JSON. The request URL might be wrong or the service might be unavailable.", + ); + } let errJson; try { errJson = await httpResponse.json();