Reference
Error Handling
Every generated project ships with a stack-aware globalErrorHandler.middleware.ts that maps ORM and validator errors into a single consistent JSON shape.
Consistent response shape
Every error your API emits follows the same shape:
json
{
"success": false,
"message": "Validation Error",
"errorSources": [
{ "path": "email", "message": "Invalid email address" }
]
}What's handled automatically
| Stack | Handled automatically |
|---|---|
| Mongoose | CastError, ValidationError, Duplicate Key (11000) |
| Prisma | P2002 (Duplicate), P2025 (Not Found), P2003 (Invalid Ref) |
| Drizzle / pg | Constraint violation codes (23505, 23503) |
| Zod | ZodError issues (v3 & v4 compatible) |
| Joi | Validation errors |
Throwing your own errors
Use the generated AppError class to throw typed HTTP errors from any service or controller:
ts
import AppError from '../../errors/AppError';
import { StatusCodes } from 'http-status-codes';
if (!user) {
throw new AppError(StatusCodes.NOT_FOUND, 'User not found');
}