All Cognest errors extend CognestError and include a machine-readable error code:
| Error Class | Code | Description |
|---|
| AuthenticationError | AUTH_FAILED | Invalid or expired API key |
| IntegrationError | INTEGRATION_* | Integration-specific failures |
| RateLimitError | RATE_LIMITED | API rate limit exceeded |
| ThinkEngineError | ENGINE_* | LLM provider errors |
| SkillError | SKILL_* | Skill execution failures |
| ConfigError | CONFIG_INVALID | Invalid configuration |
| WebhookError | WEBHOOK_* | Webhook verification or processing failures |
import { Cognest, CognestError, RateLimitError, IntegrationError } from '@cognest/sdk'
const cognest = new Cognest()
try {
const reply = await cognest.think('Hello!')
await cognest.integration('whatsapp').send(userId, reply)
} catch (error) {
if (error instanceof RateLimitError) {
console.log(`Rate limited. Retry after ${error.retryAfter}ms`)
// Automatic retry is built-in, but you can handle manually
} else if (error instanceof IntegrationError) {
console.log(`Integration ${error.integration} failed: ${error.message}`)
console.log(`Error code: ${error.code}`)
} else if (error instanceof CognestError) {
console.log(`Cognest error [${error.code}]: ${error.message}`)
} else {
throw error
}
}
// Catch all unhandled errors
cognest.on('error', (error) => {
console.error(`[Global] ${error.code}: ${error.message}`)
// Send to your error tracking service
Sentry.captureException(error, {
tags: {
cognest_code: error.code,
integration: error.integration ?? 'none',
},
})
})
// Catch per-integration errors
cognest.integration('whatsapp').on('error', (error) => {
console.error(`[WhatsApp] ${error.message}`)
})
Cognest includes automatic retry with exponential backoff for transient errors:
# cognest.config.yaml
server:
retry:
max_attempts: 3 # Maximum retry attempts
initial_delay: 1000 # First retry delay (ms)
max_delay: 30000 # Maximum delay between retries
backoff_multiplier: 2 # Exponential backoff factor
retryable_codes: # Only retry these error types
- RATE_LIMITED
- INTEGRATION_TIMEOUT
- ENGINE_OVERLOADED
| Code | Cause | Resolution |
|---|
| AUTH_FAILED | Invalid API key | Check COGNEST_API_KEY is correct |
| AUTH_EXPIRED | Token has expired | Refresh tokens via cognest.auth.refresh() |
| AUTH_INSUFFICIENT_SCOPE | Missing permissions | Request additional OAuth scopes |
| Code | Cause | Resolution |
|---|
| INTEGRATION_NOT_FOUND | Integration not configured | Add integration to config or register with cognest.use() |
| INTEGRATION_TIMEOUT | Platform API timed out | Retry or check platform status |
| INTEGRATION_AUTH_FAILED | Platform credentials invalid | Update integration credentials |
| INTEGRATION_RATE_LIMITED | Platform rate limit hit | Reduce request frequency |
| Code | Cause | Resolution |
|---|
| ENGINE_PROVIDER_ERROR | LLM provider returned an error | Check provider status or try a different model |
| ENGINE_OVERLOADED | Provider is overloaded | Retry with backoff |
| ENGINE_CONTEXT_TOO_LONG | Input exceeds context window | Reduce max_history or truncate input |
| ENGINE_INVALID_RESPONSE | Model returned unparseable output | Adjust system prompt or temperature |