Skip to main content
Proper error handling is crucial for building reliable email systems. This guide covers error types, rate limit handling, and retry strategies.

Error Types

The Resend Go SDK provides several error types for different scenarios:
Returned when you exceed your rate limit. Contains metadata about limits and retry timing.
Returned for client-side errors like invalid parameters or missing required fields.
Returned when required fields are missing before making an API request.
Returned for individual email failures in batch requests.

Basic Error Handling

Always check for errors after API calls:

Handle Rate Limits

Rate limits protect the API from abuse. Handle them gracefully with automatic retry:
1

Check for rate limit errors

Use errors.Is to detect rate limit errors:
2

Extract rate limit details

Get detailed information about the rate limit:
3

Implement retry logic

Wait and retry based on the RetryAfter value:

Complete Rate Limit Example

Here’s a complete example from examples/handle_rate_limit.go:
examples/handle_rate_limit.go

Advanced Retry Strategies

Exponential Backoff

Retry with increasing delays between attempts:

Retry with Context Timeout

Limit total retry time using context:

Handle Validation Errors

Catch and handle invalid request errors:
Validation errors indicate a problem with your request parameters. Don’t retry these errors - fix the input instead.

Handle Batch Errors

When sending batch emails, some may succeed while others fail:

Error Handling Best Practices

Always Check Errors

Never ignore error returns from API calls. Always check and handle them appropriately.

Use Idempotency Keys

When retrying, use idempotency keys to prevent duplicate emails:

Don't Retry Validation Errors

Validation errors indicate bad input. Fix your parameters instead of retrying.

Respect Rate Limits

Always use the RetryAfter value from rate limit errors. Don’t retry immediately.

Set Timeouts

Use context timeouts to prevent indefinite retries:

Log Errors

Log errors with context to help debugging:

Next Steps

Custom Client

Configure HTTP client with custom retry logic

Basic Usage

Learn the fundamentals of sending emails

Templates

Use email templates with dynamic variables

API Reference

View complete API documentation