From f51ff50e161a2760f63fa9e75320ccf0ad136685 Mon Sep 17 00:00:00 2001 From: Rafael Date: Sun, 25 May 2025 07:59:16 +0100 Subject: [PATCH] fix: return raw response Ensure the API returns the raw response when the SDK is unable to parse it, allowing for easier debugging of the issue encountered. --- src/services/api.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/services/api.ts b/src/services/api.ts index 500ee36..14250e3 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -38,8 +38,18 @@ export class APIService { throw new SquareCloudAPIError("SERVER_UNAVAILABLE", "Try again later"); } - const data = await response.json().catch(() => { - throw new SquareCloudAPIError("CANNOT_PARSE_RESPONSE", "Try again later"); + const data = await response.json().catch(async (parseError) => { + const responseText = await response + .clone() + .text() + .catch(() => "Failed to read raw response body."); + throw new SquareCloudAPIError( + "CANNOT_PARSE_RESPONSE", + `Raw API response: ${responseText}`, + { + cause: parseError, + }, + ); }); if (!data || data.status === "error" || !response.ok) {