req-error

2.0.1 • Public • Published

req-error

This package makes catch async & custom error concepts in any app easier.

Features

  • TypeScript full support
  • Custom Error with message and statusCode
  • Error catcher function with a geart durablity
  • Error handler with common situations
npm package

Installation

  • with npm
npm i req-error
  • with yarn
yarn add req-error
  • with pnpm
pnpm add req-error



Express

Configure your application with whatever configuration you want.

Basic Usage:

/* 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)
})



Some possible usages of ReqError:

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]

Some possible usages of catchError:

// 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 ❤️.

Readme

Keywords

none

Package Sidebar

Install

npm i req-error

Weekly Downloads

0

Version

2.0.1

License

ISC

Unpacked Size

30.6 kB

Total Files

42

Last publish

Collaborators

  • nazmussayad