Error Handling Pattern
Implement consistent, type-safe error handling across your application with custom error classes, API wrappers, and React error boundaries.
What's Included#
- Custom error class hierarchy (AppError, NotFoundError, UnauthorizedError, ValidationError, RateLimitError)
- Consistent JSON error response format with error codes and messages
- API route handler wrapper that catches and formats all error types including Zod errors
- Client-side API request helper with typed error handling
- Structured error logging with context (request ID, user ID, path)
- React error boundary component and toast notification integration
Usage#
Via CLI#
Loading code block...
Via AI Assistant#
Ask your AI assistant:
- "Use the error handling pattern from Bootspring"
- "Apply the Bootspring error handling pattern to my project"
Key Considerations#
- Use specific error classes for each scenario to enable programmatic error handling by code
- Never expose internal error details in production; sanitize messages for end users
- Log errors with rich context (request ID, user ID, path) for effective debugging
- Use React error boundaries to prevent component crashes from breaking the entire page
- Always show user-friendly messages via toast notifications for client-side errors
Related Patterns#
- Validation - Input validation errors
- Forms - Form error display
- Monitoring - Error tracking in production