Global Error Handler
All errors are caught by the global error handler insrc/app.ts:72:
Zod Validation Errors
What is ZodError?
ZodError is thrown when request validation fails (invalid body, params, or query).
Handling
The error handler prettifies Zod errors and returns a 400 Bad Request:Example Response
HTTP Errors (ky)
What is HTTPError?
HTTPError from the ky HTTP client is thrown when external API requests fail.
Handling
The error handler extracts the response body and returns a 400 Bad Request:Example Response
HTTP Exceptions (Hono)
What is HTTPException?
HTTPException is Hono’s built-in HTTP error class for throwing HTTP errors.
Usage
Handling
The error handler returns the exception’s response directly:Unknown Errors
All other errors are treated as internal server errors (500):Example Response
Request ID Tracking
Every request gets a unique ID via therequestId middleware (src/app.ts:52):
Accessing Request ID
In route handlers:Response Headers
The request ID is included in response headers:404 Not Found Handler
Handles routes that don’t exist (src/app.ts:105):
HTTP Status Codes
The app uses constants for HTTP status codes (defined insrc/core/constants/http.ts):
Custom Error Responses
Creating Custom Errors
Structured Error Response
Logging
All errors are logged with context using the custom logger (src/core/utils/logger.ts):
- Error type
- Request ID
- Error message/details
- Timestamp
- Stack trace (for unknown errors)
Timeout Handling
Requests that exceed 15 seconds are automatically terminated (src/app.ts:24):
