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.
This commit is contained in:
tusharmagar 2026-04-01 15:20:49 +05:30
parent 8ea1500ab9
commit ecfe07eb6f

View file

@ -167,7 +167,15 @@ export async function composioApiCall<T extends z.ZodTypeAny>(
}
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')) {