Error Handling
Handle typed OpenSES API errors and rate limits.
All HTTP errors extend OpenSESError.
import {
AuthenticationError,
ConflictError,
NotFoundError,
OpenSESError,
PermissionError,
RateLimitError,
ValidationError,
} from '@openses/openses';Example
try {
await client.emails.send({
from: 'noreply@example.com',
to: 'user@example.com',
subject: 'Hello',
text: 'Hello',
});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Invalid or revoked API key');
} else if (error instanceof ValidationError) {
console.error(error.details);
} else if (error instanceof RateLimitError) {
console.error(`Retry after ${error.retryAfter ?? 60} seconds`);
} else if (error instanceof OpenSESError) {
console.error(error.statusCode, error.code, error.message);
}
}| Error | Status | Meaning |
|---|---|---|
ValidationError | 400 or 422 | Request validation failed |
AuthenticationError | 401 | API key is missing, invalid, or revoked |
PermissionError | 403 | The project cannot perform the action |
NotFoundError | 404 | The requested email was not found |
ConflictError | 409 | The resource state does not allow the action |
RateLimitError | 429 | Retry after retryAfter seconds |
InternalServerError | 500+ | OpenSES failed to process the request |