@i4you/http-errors
v0.0.2
Published
This will create common http errors
Readme
@I4You/http-errors
Custom HTTP Error Generator for Express.js and microservices.
Install
npm install @i4you/http-errors
# or
yarn add @i4you/http-errorsUsage
import { createError } from '@i4you/http-errors';
// Named Error
next(createError.NotFound('User not found', 'USER_NOT_FOUND'));
// Generic Error
next(createError(400, 'Bad request data', 'BAD_REQUEST'));
// Optional: Throw instead of next()
throw createError.Internal('Database error', 'DB_ERROR');Stack Trace
Clean stack traces that point directly to your code:
HttpError: Not Found
at routeHandler (/app/routes/user.ts:10:13)API
createError(statusCode: number, message: string, errorCode?: string, data?: any)
createError.BadRequest(message?: string, errorCode?: string, data?: any)
createError.NotFound(...)
createError.Internal(...)
...License
MIT
