This package makes catch async & custom error concepts in any app easier.
- TypeScript full support
- Custom Error with message and statusCode
- Error catcher function with a geart durablity
- Error handler with common situations
- with npm
npm i req-error
- with yarn
yarn add req-error
- with pnpm
pnpm add req-error
Configure your application with whatever configuration you want.
/* controller.js */
// Make ReqError global (Recommended)
require('req-error/global')
const { catchError } = require('req-error')
// Not Global (Not Recommended)
const { default: ReqError, catchError } = require('req-error')
const login = catchError((req, res) => {
// Do your stuff...
throw new ReqError('This is just a demo', 400)
})
const signup = catchError(async (req, res) => {
// Do your stuff...
throw new ReqError('This is just another demo', 401)
})
new ReqError('Message', 404)
// { message: "Message", statusCode: 404 }
new ReqError(['Message', 404])
// { message: "Message", statusCode: 404 }
new ReqError(['Message', 404], 500)
// { message: "Message", statusCode: 500 }
// Even more simple:
throw 'Error message'
throw ['Error message', 404]
// catchError(arg,...)
catchError(Function)
// Function
catchError(Function, String)
// [Function, String]
catchError(Function, Function, Function)
// [Function, Function, Function]
catchError([Function])
// [Function]
catchError([Function, Function], Function)
// [[Function, Function], Function]
catchError({ login: Function })
// { login: Function }
catchError(require('./login.js'))
// { login: Function }
catchError(require('./login.js'), require('./signup.js'))
// [{ login: Function }, { signup: Function }]
catchError(Function, [Function, Function], { login: Function })
// [Function, [Function, Function], { login: Function }]
Made by Nazmus Sayad with ❤️.