commit 0e434a26df32fd1e6b15713dd5c2433728913697
parent fb47c45cc4cf83ada053d5b03e1c71652bce9dbe
Author: Sebastian <sebasjm@gmail.com>
Date: Wed, 26 Jun 2024 09:04:17 -0300
add response when http response is malformed, good for debug
Diffstat:
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/packages/challenger-ui/src/hooks/session.ts b/packages/challenger-ui/src/hooks/session.ts
@@ -121,7 +121,7 @@ export function useSessionState(): SessionStateHandler {
});
return;
}
- // current status, FIXME: better check to know if the sate changed
+ // current status, FIXME: better check to know if the state changed
const ls = state.lastStatus;
if (
ls.changes_left !== st.changes_left ||
diff --git a/packages/taler-util/src/errors.ts b/packages/taler-util/src/errors.ts
@@ -107,6 +107,10 @@ export interface DetailsMap {
requestUrl: string;
requestMethod: string;
httpStatusCode: number;
+ /**
+ * Original response which is malformed
+ */
+ response?: string;
validationError?: string;
/**
* Content type of the response, usually only specified if not the
diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts
@@ -154,6 +154,7 @@ export async function readTalerErrorResponse(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
validationError: e.toString(),
},
"Couldn't parse JSON format from error response",
@@ -173,6 +174,7 @@ export async function readTalerErrorResponse(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
},
"Error response did not contain error code",
);
@@ -193,6 +195,7 @@ export async function readUnexpectedResponseDetails(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
validationError: e.toString(),
},
"Couldn't parse JSON format from error response",
@@ -206,6 +209,7 @@ export async function readUnexpectedResponseDetails(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
},
"Error response did not contain error code",
);
@@ -242,6 +246,7 @@ export async function readSuccessResponseJsonOrErrorCode<T>(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
validationError: e.toString(),
},
"Couldn't parse JSON format from response",
@@ -257,6 +262,7 @@ export async function readSuccessResponseJsonOrErrorCode<T>(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
validationError: e.toString(),
},
"Response invalid",
@@ -282,6 +288,7 @@ export async function readResponseJsonOrErrorCode<T>(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
validationError: e.toString(),
},
"Couldn't parse JSON format from response",
@@ -297,6 +304,7 @@ export async function readResponseJsonOrErrorCode<T>(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
validationError: e.toString(),
},
"Response invalid",
@@ -376,6 +384,7 @@ export async function readSuccessResponseTextOrErrorCode<T>(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
validationError: e.toString(),
},
"Couldn't parse JSON format from error response",
@@ -389,6 +398,7 @@ export async function readSuccessResponseTextOrErrorCode<T>(
{
httpStatusCode: httpResponse.status,
requestUrl: httpResponse.requestUrl,
+ response: await httpResponse.text(),
requestMethod: httpResponse.requestMethod,
},
"Error response did not contain error code",
@@ -420,6 +430,7 @@ export async function checkSuccessResponseOrThrow(
requestUrl: httpResponse.requestUrl,
requestMethod: httpResponse.requestMethod,
httpStatusCode: httpResponse.status,
+ response: await httpResponse.text(),
validationError: e.toString(),
},
"Couldn't parse JSON format from error response",
@@ -433,6 +444,7 @@ export async function checkSuccessResponseOrThrow(
{
httpStatusCode: httpResponse.status,
requestUrl: httpResponse.requestUrl,
+ response: await httpResponse.text(),
requestMethod: httpResponse.requestMethod,
},
"Error response did not contain error code",