Error Handling Overview
Consistent Responses
Standardized error format Client-friendly
Status Codes
HTTP status codes RESTful standard
Clear Messages
Developer-friendly User-friendly
Logging
Error tracking Debugging support
SoException
Sonamu provides error classes based onSoException. When you throw a SoException, the framework automatically sends an appropriate HTTP status code and structured error response.
Basic Usage
Available Exception Classes
These are the exception classes provided by Sonamu. All inherit fromSoException.
SoException Constructor
All exception classes share the same constructor signature.message: Error message. Supports localized strings (LocalizedString).payload: Additional information. Can pass Zod validation issue arrays, etc.
Usage Examples
Various Error Situations
Passing Detailed Info via payload
isSoException Type Guard
Zod Validation Error Handling
When you pass a Zod issue array toBadRequestException’s payload, Sonamu’s error handler automatically includes validation error details in the response.
Converting Zod Errors
Error Response Format
Sonamu’s built-in error handler responds in the following format.Basic Error Response
Zod Validation Error Response (when issue array is passed as payload)
Customizing the Error Handler
Sonamu includes a built-in error handler, but you can set a custom error handler via thelifecycle.onError option in startServer if needed.
Status Code Reference
Standard HTTP Status Codes
Sonamu Custom Status Codes
Practical Pattern
Cautions
Next Steps
Automatic Validation
Zod-based validation
Custom Validation
Custom validation logic
@api Decorator
API basic usage
Context
SonamuContext