Error Handling
Guide to handling errors in requests.
The SDK defines specific error classes to handle various issues:
import { SectonError, AuthenticationError, RateLimitError, NetworkError } from 'secton';
try {
const result = await client.chat(messages);
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Invalid API key');
} else if (error instanceof RateLimitError) {
console.error(`Rate limited. Retry after ${error.retryAfter}s`);
} else if (error instanceof NetworkError) {
console.error('Network error:', error.message);
} else {
console.error('Unknown error:', error);
}
}
Proper error handling ensures robust application behavior and user experience.
Last updated
Was this helpful?