OpenSES

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);
  }
}
ErrorStatusMeaning
ValidationError400 or 422Request validation failed
AuthenticationError401API key is missing, invalid, or revoked
PermissionError403The project cannot perform the action
NotFoundError404The requested email was not found
ConflictError409The resource state does not allow the action
RateLimitError429Retry after retryAfter seconds
InternalServerError500+OpenSES failed to process the request

On this page