2.0.2 • Published 8 months ago

req-error v2.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

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

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

2.0.2

8 months ago

1.0.26

2 years ago

1.0.25

2 years ago

2.0.1

2 years ago

1.0.24

2 years ago

2.0.0

2 years ago

1.0.23

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.19

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago