The SDK uses a try-catch wrapper around all API requests. Instead of throwing exceptions, SDK methods return either the successful response data or an error object.
Check if a response is an error by verifying the presence of the error property:
const result = await recall.bot.create({ meeting_url: 'https://meet.google.com/abc-defg-hij'});if ('error' in result) { // Handle error console.error(`Error: ${result.status}`, result.error);} else { // Success - use result.data console.log('Bot created:', result.id);}
All SDK methods return a promise that resolves to either the response data or a RecallError object. Errors are never thrown, so you don’t need traditional try-catch blocks.
Status code: 401 UnauthorizedOccurs when your API key is invalid or missing.
const result = await recall.bot.list({});if ('error' in result && result.status === 401) { console.error('Authentication failed. Check your API key.');}
For TypeScript users, you can create a type guard to check for errors:
function isRecallError(result: any): result is RecallError { return 'error' in result && 'status' in result;}const result = await recall.bot.create(params);if (isRecallError(result)) { // TypeScript knows result is RecallError console.error(`Error ${result.status}:`, result.error);} else { // TypeScript knows result is CreateResponse console.log('Bot ID:', result.id);}
Every SDK method can return an error object. Always check the response before accessing data properties.
const result = await recall.bot.retrieve({ id: botId });if ('error' in result) { return; // Handle error}// Safe to access result propertiesconsole.log(result.id);
Log error details
The error object contains detailed information from the API. Log both the status code and error message for debugging.
if ('error' in result) { console.error('API Error:', { status: result.status, error: result.error });}
Implement retry logic
For transient errors (like network timeouts or 5xx server errors), implement retry logic with exponential backoff.
async function createBotWithRetry(params: CreateParams, maxRetries = 3) { for (let i = 0; i < maxRetries; i++) { const result = await recall.bot.create(params); if (!('error' in result)) { return result; // Success } // Retry on 5xx errors if (result.status >= 500 && i < maxRetries - 1) { await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, i))); continue; } return result; // Return error after retries exhausted }}
Handle different error types
Different status codes require different handling strategies. Use a switch statement or if-else chain to handle errors appropriately.
if ('error' in result) { switch (result.status) { case 401: // Refresh credentials or redirect to login break; case 403: // Show permission denied message break; case 404: // Resource not found break; case 429: // Rate limit - implement backoff break; default: // Generic error handling break; }}