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

StackHandled automatically
MongooseCastError, ValidationError, Duplicate Key (11000)
PrismaP2002 (Duplicate), P2025 (Not Found), P2003 (Invalid Ref)
Drizzle / pgConstraint violation codes (23505, 23503)
ZodZodError issues (v3 & v4 compatible)
JoiValidation 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');
}