diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-util/src/http-common.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts index da2fbb9da..e934c07f7 100644 --- 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(); |