Error Handling
Rules
- Structured error types:
class AppError extends Error { code: string; statusCode: number } - Error boundaries in React for crash recovery — show fallback UI, log error
- Graceful degradation: feature fails → show message, don't crash app
- User-friendly messages: "Something went wrong" not stack traces
- Log errors with context: user ID, request ID, timestamp, error code
- Retry transient errors (network, 502, 429) with exponential backoff — max 3 retries
- Fail fast on validation errors — return 400 immediately, don't process further
- Never swallow errors with empty catch blocks — at minimum, log them