ChurnKitError
All SDK methods throwChurnKitError on failure. It extends Error and adds status (HTTP status code) and code (typed error constant).
Error codes
| Code | HTTP | When |
|---|---|---|
ABORTED | — | The caller’s AbortSignal fired |
TIMEOUT | — | Request exceeded configured timeout |
NETWORK_ERROR | — | DNS failure, connection refused, etc. |
VALIDATION_ERROR | 400 | Invalid input (empty userId, bad threshold, etc.) |
UNAUTHORIZED | 401 | API key is missing, invalid, or revoked |
FORBIDDEN | 403 | API key lacks permission for this operation |
NOT_FOUND | 404 | Resource doesn’t exist (user not tracked, no watch, etc.) |
RATE_LIMITED | 429 | Too many requests — back off and retry |
SERVER_ERROR | 5xx | ChurnKit server error |
PAYLOAD_TOO_LARGE | 413 | bulkEvent() exceeded 500 items |
Handling patterns
Ignore cancellations
Exhaustive switch with type narrowing
Non-blocking with error logging
isKnownErrorCode()
Type guard that narrowserr.code to a well-known ErrorCode constant — useful for exhaustive switch statements.