Errors

All failure paths use a small, predictable hierarchy:

ErrorMeaning
SdkValidationErrorA request argument failed an OpenAPI constraint before network I/O.
SdkHttpErrorThe server returned a non-2xx response.
SdkApiErrorA 2xx response whose error envelope, when the API declares one, reports a failed call. It carries the envelope's error code.
SdkResponseDecodeErrorA 2xx response body or stream event did not decode into its declared type. It keeps the raw body.
SdkNetworkErrorDNS, connection, TLS, or socket failure.
SdkTimeoutErrorThe configured per-attempt timeout elapsed.

HTTP errors expose statusCode, the response body and headers, plus requestId when the server supplies one. Preserve the request ID in support logs; it is the fastest way to correlate a failed SDK call with server-side traces.

Common statuses are reported as a subclass of SdkHttpError, so a handler can catch only the one it handles: SdkBadRequestError (400), SdkUnauthorizedError (401), SdkPermissionDeniedError (403), SdkNotFoundError (404), SdkConflictError (409), SdkUnprocessableEntityError (422), SdkRateLimitError (429), SdkInternalServerError (any 5xx). Any other status is reported as SdkHttpError itself.

When the API declares a model for an error response, the SDK decodes the body into it as error.data, typed as the SdkErrorBody union of those models. It is empty when the status declares no model or the body does not fit one. The raw body stays on the error either way, and deserializeModel<ErrorModel>(error.body, "ErrorModel") decodes it into any ErrorModel by hand.

An operation that declares error models also exports <Operation>Error, the union of those models, for typing a decoded body.

Handling an error

ts
import { SdkHttpError, SdkNetworkError, SdkTimeoutError } from "@octridev/resend";

try {
  // any operation
} catch (error) {
  if (error instanceof SdkHttpError) {
    console.error("Request failed", error.statusCode, error.requestId);
  } else if (error instanceof SdkNetworkError || error instanceof SdkTimeoutError) {
    console.error("Transport failed", error.message);
  }
  throw error;
}