Skip to content
You're viewing documentation for v0.6.4. It may be out of date.Go to latest
Email SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Errors

Every Email SDK error class and code, the retryable flag, and how to branch on failures in application code.

Every error the SDK throws is an EmailSdkError (or subclass) with a machine-readable code and a retryable flag. Three subclasses narrow the common cases:

Properties

All four classes carry the same fields (plus the standard Error message and cause):

PropType
codestring

Machine-readable error code. Branch on this, not on message text.

Typestring
retryableboolean

Whether retrying the same adapter is reasonable.

Typeboolean
Defaultfalse
provider?string

Routing name of the adapter that failed, when known.

Typestring
status?number

HTTP status from the provider, when there was one.

Typenumber
details?unknown

Parsed provider error body, validation context, or collected failures.

Typeunknown

Classes and codes

Class Code Thrown when
EmailValidationError validation_error The message fails validation, an adapter rejects unsupported fields, or client config is invalid (duplicate adapter/plugin, no adapters). Never retryable.
EmailProviderNotFoundError provider_not_found A routing name is not registered — Email provider "x" is not registered. Never retryable.
EmailProviderError provider_error A provider request fails: non-2xx response or network error. status and details carry the provider’s answer.
EmailSdkError all_providers_failed Two or more routes were attempted and all failed. details holds one error per adapter, in route order.
EmailSdkError retry_loop_exited Internal guard for an impossible retry-loop exit. Treat as a bug if seen.

When only one route was attempted, its error is rethrown as-is — all_providers_failed only appears after a multi-adapter route exhausts every option. Errors adapters throw that are not already EmailProviderError are wrapped into one, keeping the original as cause (or in details for non-Error values).

What counts as retryable

retryable: true is set for failures that may succeed on a re-attempt:

  • HTTP 408, 409, 425, 429, and any 5xx
  • Network failures: ECONNRESET-family error codes, fetch failed, socket and timeout errors

Everything else is non-retryable: 4xx like 401/422, validation errors, unknown routing names, and aborted requests (AbortError). This classification drives the default retry policy — see fallbacks and retries.

isRetryableEmailError(error)

Returns true only for an EmailSdkError with retryable: true; any other value returns false. It is the default shouldRetry predicate, and safe to call on anything a catch block hands you.

Handling errors in app code

Branch on class first, then on code and retryable:

Inside a send, you rarely handle retries yourself — configure the client’s retry and fallback options and let the SDK exhaust them before anything reaches your catch.

Last updated on