gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: catch json parsing problem an


From: gnunet
Subject: [taler-wallet-core] branch master updated: catch json parsing problem and report nicely
Date: Tue, 18 Apr 2023 19:58:45 +0200

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 7330f0daf catch json parsing problem and report nicely
7330f0daf is described below

commit 7330f0daf907133876baf8831c44ec34cec326e5
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Tue Apr 18 14:58:34 2023 -0300

    catch json parsing problem and report nicely
---
 packages/taler-util/src/http-common.ts | 83 ++++++++++++++++++++++++++++++++--
 1 file changed, 78 insertions(+), 5 deletions(-)

diff --git a/packages/taler-util/src/http-common.ts 
b/packages/taler-util/src/http-common.ts
index 1329c8a55..9aaad12c7 100644
--- a/packages/taler-util/src/http-common.ts
+++ b/packages/taler-util/src/http-common.ts
@@ -139,7 +139,22 @@ type ResponseOrError<T> =
 export async function readTalerErrorResponse(
   httpResponse: HttpResponse,
 ): Promise<TalerErrorDetail> {
-  const errJson = await httpResponse.json();
+  let errJson;
+  try {
+    errJson = await httpResponse.json();
+  } catch (e: any) {
+    throw TalerError.fromDetail(
+      TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
+      {
+        requestUrl: httpResponse.requestUrl,
+        requestMethod: httpResponse.requestMethod,
+        httpStatusCode: httpResponse.status,
+        validationError: e.toString(),
+      },
+      "Couldn't parse JSON format from error response",
+    );
+  }
+
   const talerErrorCode = errJson.code;
   if (typeof talerErrorCode !== "number") {
     logger.warn(
@@ -163,7 +178,21 @@ export async function readTalerErrorResponse(
 export async function readUnexpectedResponseDetails(
   httpResponse: HttpResponse,
 ): Promise<TalerErrorDetail> {
-  const errJson = await httpResponse.json();
+  let errJson;
+  try {
+    errJson = await httpResponse.json();
+  } catch (e: any) {
+    throw TalerError.fromDetail(
+      TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
+      {
+        requestUrl: httpResponse.requestUrl,
+        requestMethod: httpResponse.requestMethod,
+        httpStatusCode: httpResponse.status,
+        validationError: e.toString(),
+      },
+      "Couldn't parse JSON format from error response",
+    );
+  }
   const talerErrorCode = errJson.code;
   if (typeof talerErrorCode !== "number") {
     return makeErrorDetail(
@@ -198,7 +227,21 @@ export async function 
readSuccessResponseJsonOrErrorCode<T>(
       talerErrorResponse: await readTalerErrorResponse(httpResponse),
     };
   }
-  const respJson = await httpResponse.json();
+  let respJson;
+  try {
+    respJson = await httpResponse.json();
+  } catch (e: any) {
+    throw TalerError.fromDetail(
+      TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
+      {
+        requestUrl: httpResponse.requestUrl,
+        requestMethod: httpResponse.requestMethod,
+        httpStatusCode: httpResponse.status,
+        validationError: e.toString(),
+      },
+      "Couldn't parse JSON format from response",
+    );
+  }
   let parsedResponse: T;
   try {
     parsedResponse = codec.decode(respJson);
@@ -267,7 +310,22 @@ export async function 
readSuccessResponseTextOrErrorCode<T>(
   httpResponse: HttpResponse,
 ): Promise<ResponseOrError<string>> {
   if (!(httpResponse.status >= 200 && httpResponse.status < 300)) {
-    const errJson = await httpResponse.json();
+    let errJson;
+    try {
+      errJson = await httpResponse.json();
+    } catch (e: any) {
+      throw TalerError.fromDetail(
+        TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
+        {
+          requestUrl: httpResponse.requestUrl,
+          requestMethod: httpResponse.requestMethod,
+          httpStatusCode: httpResponse.status,
+          validationError: e.toString(),
+        },
+        "Couldn't parse JSON format from error response",
+      );
+    }
+
     const talerErrorCode = errJson.code;
     if (typeof talerErrorCode !== "number") {
       throw TalerError.fromDetail(
@@ -296,7 +354,22 @@ export async function checkSuccessResponseOrThrow(
   httpResponse: HttpResponse,
 ): Promise<void> {
   if (!(httpResponse.status >= 200 && httpResponse.status < 300)) {
-    const errJson = await httpResponse.json();
+    let errJson;
+    try {
+      errJson = await httpResponse.json();
+    } catch (e: any) {
+      throw TalerError.fromDetail(
+        TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE,
+        {
+          requestUrl: httpResponse.requestUrl,
+          requestMethod: httpResponse.requestMethod,
+          httpStatusCode: httpResponse.status,
+          validationError: e.toString(),
+        },
+        "Couldn't parse JSON format from error response",
+      );
+    }
+
     const talerErrorCode = errJson.code;
     if (typeof talerErrorCode !== "number") {
       throw TalerError.fromDetail(

-- 
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]