mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-30 19:06:23 +02:00
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:
parent
8ea1500ab9
commit
ecfe07eb6f
1 changed files with 9 additions and 1 deletions
|
|
@ -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')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue