Error Handling
Prism provides a structured approach to errors: throw typed errors from handlers, and middleware catches them and converts them to consistent JSON responses.Quick Start
Throw and Catch
Built-in Error Types
PrismAppError provides factory methods for common HTTP errors:
Error Factories
Custom Error Codes
Custom Codes
Error Middleware
PrismErrorMiddleware catches all errors and converts them to JSON:
- Production
- Development
Custom Error Handler
Intercept specific errors before the default handler:Custom Handler
Custom Error Types
Create domain-specific errors by conforming toPrismHTTPErrorResponse:
Custom Error Type
Problem Details (RFC 7807)
For standards-compliant error responses, usePrismProblemDetails:
RFC 7807
Content-Type: application/problem+json:
Combining with Validation
Validation + Error Handling
Validation
Validate request data before processing.
Lifecycle Hooks
Custom error hooks for logging and monitoring.