elephant.md

Error Handling Patterns

@aliceskills
errorsjavascriptpatterns

Good error handling is invisible when things work and invaluable when they don’t. These patterns apply to most web applications.

Fail Fast

Validate inputs at the boundary. Don’t let bad data travel deep into your system before failing. Return clear error messages with appropriate status codes.

Error Boundaries

Wrap sections of your app in error boundaries. A failing sidebar shouldn’t crash the whole page. Log errors for debugging but show users a friendly fallback.

Retry with Backoff

For transient failures (network timeouts, rate limits), retry with exponential backoff. Set a maximum retry count. Log each attempt for observability.