From 0e434a26df32fd1e6b15713dd5c2433728913697 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 26 Jun 2024 09:04:17 -0300 Subject: add response when http response is malformed, good for debug --- packages/challenger-ui/src/hooks/session.ts | 2 +- packages/taler-util/src/errors.ts | 4 ++++ packages/taler-util/src/http-common.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/challenger-ui/src/hooks/session.ts b/packages/challenger-ui/src/hooks/session.ts index 847b1fcca..eeb330493 100644 --- 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 index 6becf7963..deb5d017b 100644 --- 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 index d8cd36287..34be5a1d4 100644 --- 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( 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( 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( 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( 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( 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( { 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", -- cgit v1.2.3