gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: improve error message when er


From: gnunet
Subject: [taler-wallet-core] branch master updated: improve error message when error response doesn't even contain JSON
Date: Tue, 21 Nov 2023 11:51:15 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 342df60ab improve error message when error response doesn't even 
contain JSON
342df60ab is described below

commit 342df60abe6d8b8b0c51e79cf13c7edcca58d9f9
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue Nov 21 11:51:14 2023 +0100

    improve error message when error response doesn't even contain JSON
---
 packages/taler-util/src/http-common.ts | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

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();

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]