Skip to content
atarashi
Documentation menu

mw/error-handler

One consistent JSON error shape: an HttpError class, Zod validation mapping and no stack leaks.

Provides: middleware:error-handler

Requires: http, validation, config:env

Files it writes

  • src/lib/http-error.ts (when provides('language:typescript'))
  • src/lib/http-error.js (when provides('language:javascript'))
  • src/middlewares/error-handler.ts (when provides('language:typescript') && has('http/express'))
  • src/middlewares/error-handler.js (when provides('language:javascript') && has('http/express'))

What it contributes to other files

FileSlotLine
src/app.ts|jsimportsimport { errorHandler } from './middlewares/error-handler.js';
src/app.ts|jserror-handlersapp.use(errorHandler);
src/app.ts|jsimportsimport { HttpError } from './lib/http-error.js';
src/app.ts|jsimportsimport { ZodError } from 'zod';
src/app.ts|jserror-handlersapp.setErrorHandler(async (error, _request, reply) => {
src/app.ts|jserror-handlersapp.onError((error, c) => {

Use it

atarashi new my-app --add mw/error-handler
atarashi add mw/error-handler

Version 1.0.0. Format reference: Authoring blueprints.

Part of the atarashi documentation, written and maintained by Gautam Suthar.