The result-object model
There are two result types:ResultfromsendEmailEmailStatusResultfromgetEmailStatus
success, errorMessage, and statusCode. EmailStatusResult adds errorCode, which is useful for programmatic handling of status lookup failures.
Result fields
boolean
required
true for success, false for any failure.string
Human-readable description of what went wrong.
number
HTTP status code from the API response. Absent for client-side validation errors and network/timeout failures.
string
Machine-readable error code. Present only on
EmailStatusResult.Error categories
1. Constructor errors (thrown)
The constructor throwsError with a descriptive message if any option is invalid. These are the only synchronous throws in the SDK.
2. Client-side validation (no statusCode)
Before any network request, the SDK validates input. These return{ success: false, errorMessage } with no statusCode:
3. API errors (statusCode present)
When the API returns a non-2xx response orsuccess !== true, the SDK extracts the error from the response body and returns:
body.error (string), body.error.message (object), body.message, or a fallback Request failed (HTTP <status> <statusText>).
4. Network and timeout (no statusCode)
Whenfetch fails or the request times out, the method resolves with:
statusCode and contain the underlying error message.
Error codes on EmailStatusResult
TheerrorCode field helps you decide how to respond programmatically:
Classifying a Result
You can write a helper that categorizes anyResult or EmailStatusResult:
classify-error.ts
Retry guidance
The SDK has no built-in retries. Implement retry logic in your application when it makes sense:- Retry: No
statusCodedue to a non-timeout network error, orstatusCode >= 500, orstatusCode === 429. - Do not retry: Client-side validation errors (
statusCodeabsent and specific message),4xxerrors other than429, timeouts (check status or log instead). - Timeout caution:
sendEmailon timeout returns nomessageId, so you cannot look up the status. Log the timeout and reconcile manually, or accept a duplicate risk explicitly before retrying.
retry-helper.ts
The helper above is application code, not an SDK feature. Adapt the retry strategy to your application’s reliability requirements and observability setup.
Converting results to exceptions
If you prefer a throw-style API, wrap the SDK calls:throw-style.ts
JavaScript example
error-handling.mjs
Sending emails
Full sendEmail reference with all validation rules and error messages.
Email status
How getEmailStatus reports errors with errorCode values.
Client configuration
Timeout settings that affect network and timeout errors.
Guides: Production best practices
Logging, monitoring, and retry strategies for production deployments.