Core
Error Handling
Handle errors with automatic retries and typed error classes
Error Classes
import { CommetAPIError, CommetValidationError } from '@commet/node'
try {
await commet.customers.create({ email: 'invalid' })
} catch (error) {
if (error instanceof CommetValidationError) {
console.log(error.validationErrors)
// { email: ['Invalid email format'] }
}
if (error instanceof CommetAPIError) {
console.log(error.statusCode, error.message)
}
}| Class | Use case |
|---|---|
CommetAPIError | HTTP errors (4xx, 5xx) |
CommetValidationError | Invalid input with field details |
CommetError | Base class for all errors |
Automatic Retries
Failed requests retry with exponential backoff (1s → 2s → 4s, max 8s).
Retryable: 408, 429, 500, 502, 503, 504
const commet = new Commet({
apiKey: process.env.COMMET_API_KEY!,
retries: 3, // default
})Non-Blocking Usage
Don't let tracking errors break your app:
commet.usage.track({
externalId: 'user_123',
eventType: 'api_call',
}).catch(console.error)
// Continue without waitingHow is this guide?