From ecfe07eb6f7842e578f35a12abf7a288ac281c1d Mon Sep 17 00:00:00 2001 From: tusharmagar Date: Wed, 1 Apr 2026 15:20:49 +0530 Subject: [PATCH] Improve error handling in Composio API calls - Enhanced error reporting by extracting human-readable messages from the JSON response body when the API call fails. - Added logic to parse the response and include specific error details in the thrown error message, improving debugging and user feedback. --- apps/x/packages/core/src/composio/client.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/x/packages/core/src/composio/client.ts b/apps/x/packages/core/src/composio/client.ts index 1efa0489..9fce564f 100644 --- a/apps/x/packages/core/src/composio/client.ts +++ b/apps/x/packages/core/src/composio/client.ts @@ -167,7 +167,15 @@ export async function composioApiCall( } if (!response.ok) { - throw new Error(`Composio API error: ${response.status} ${response.statusText}`); + // Try to extract a human-readable message from the JSON body + let detail = ''; + try { + const body = JSON.parse(rawText); + if (typeof body?.error === 'string') detail = body.error; + else if (typeof body?.message === 'string') detail = body.message; + } catch { /* body isn't JSON or has no message field */ } + const suffix = detail ? `: ${detail}` : ''; + throw new Error(`Composio API error: ${response.status} ${response.statusText}${suffix}`); } if (!contentType.includes('application/json')) {