From e0e9a41fd6f81b8faf35df8194e6a0c26b382a8a Mon Sep 17 00:00:00 2001 From: igoramf Date: Tue, 10 Mar 2026 12:18:38 -0300 Subject: [PATCH] fix: improve error logging to serialize Response objects console.error was logging raw Response objects, producing "(undefined) [object Response]" in observability tools like HyperDX. Now logs status, URL and response body for actionable debugging. --- clients/withManifest.ts | 16 ++++++++++------ utils/fetchAPI.ts | 6 +++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/clients/withManifest.ts b/clients/withManifest.ts index bf6d66ebc..7525fcfae 100644 --- a/clients/withManifest.ts +++ b/clients/withManifest.ts @@ -158,18 +158,22 @@ const fetchWithProps = async ( return response.json(); } - console.error(init?.body, response); - const error = await response.text(); + const errorBody = await response.text(); + const correlationId = response.headers.get("x-correlation-id"); + console.error( + `Invoke error ${response.status} ${response.statusText} - ${url}`, + errorBody, + ); if (response.headers.get("content-type") === "application/json") { - const errorObj = JSON.parse(error); + const errorObj = JSON.parse(errorBody); throw new InvokeError(`${response.status}: ${response.statusText}`, { cause: errorObj, - correlationId: response.headers.get("x-correlation-id"), + correlationId, }); } throw new InvokeError(`${response.status}: ${response.statusText}`, { - cause: error, - correlationId: response.headers.get("x-correlation-id"), + cause: errorBody, + correlationId, }); }; diff --git a/utils/fetchAPI.ts b/utils/fetchAPI.ts index 218025ecb..54dd1465b 100644 --- a/utils/fetchAPI.ts +++ b/utils/fetchAPI.ts @@ -14,6 +14,10 @@ export const fetchAPI = async ( return response.json(); } - console.error(input, response); + const errorBody = await response.text(); + console.error( + `fetchAPI error ${response.status} ${response.statusText} - ${input}`, + errorBody, + ); throw new Error(`fetch ${input} responded with status ${response.status}`); };