# Errors (/docs/v/0.5.0/reference/errors)



Email SDK exports four error classes.

```ts
import {
  EmailProviderError,
  EmailProviderNotFoundError,
  EmailSdkError,
  EmailValidationError,
} from "@opencoredev/email-sdk";
```

## Error fields [#error-fields]

`EmailSdkError` includes:

| Field       | Type      | Notes                                   |
| ----------- | --------- | --------------------------------------- |
| `code`      | `string`  | Machine-readable error code.            |
| `provider`  | `string`  | Routing name when available.            |
| `status`    | `number`  | HTTP status when available.             |
| `retryable` | `boolean` | Whether retry is reasonable.            |
| `details`   | `unknown` | Adapter response body or extra context. |

## Common errors [#common-errors]

| Error                        | When it happens                         |
| ---------------------------- | --------------------------------------- |
| `EmailValidationError`       | A message or client config is invalid.  |
| `EmailProviderNotFoundError` | The selected adapter is not registered. |
| `EmailProviderError`         | An adapter call fails.                  |
| `EmailSdkError`              | A general SDK-level failure occurs.     |

## Retries and fallbacks [#retries-and-fallbacks]

`retryable` means retrying the same adapter is reasonable. It is not required for fallback. After an adapter finally fails, Email SDK can advance to the next configured fallback adapter.

`EmailValidationError` from top-level message validation stops the send before adapter attempts. Adapter-specific unsupported-field validation can surface during an adapter attempt, so do not rely on fallback to fix an incompatible message shape. Choose fallback adapters that can represent the same fields your message uses.

When multiple attempted routes fail, Email SDK throws an `EmailSdkError` with code `all_providers_failed` and the collected failures in `details`.

## Handling adapter errors [#handling-adapter-errors]

```ts
try {
  await email.send(message);
} catch (error) {
  if (error instanceof EmailProviderError && error.retryable) {
    // Queue a later retry, alert, or switch to another flow.
  }

  throw error;
}
```
