# req-error

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

Latest version **2.0.2** (published 2024-10-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install req-error
pnpm add req-error
yarn add req-error
bun add req-error
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2024-10-19 |
| First published | 2022-12-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 30 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | NazmusSayad |
| Maintainers | nazmussayad |

## Links

- npm: https://www.npmjs.com/package/req-error
- Repository: https://github.com/NazmusSayad/req-error-core
- Homepage: https://github.com/NazmusSayad/req-error-core#readme
- Issues: https://github.com/NazmusSayad/req-error-core/issues
- npm.io page: https://npm.io/package/req-error

## Recent versions

- 2.0.2 (latest) — 2024-10-19
- 2.0.1 — 2023-08-03
- 2.0.0 — 2023-08-03
- 1.0.28 — 2023-06-04
- 1.0.27 — 2023-06-04
- 1.0.26 — 2023-05-29
- 1.0.25 — 2023-05-24
- 1.0.24 — 2023-05-24
- 1.0.23 — 2023-05-23
- 1.0.22 — 2023-04-20
- 1.0.21 — 2023-03-29
- 1.0.20 — 2023-03-29
- 1.0.19 — 2023-01-24
- 1.0.18 — 2023-01-11
- 1.0.17 — 2023-01-11
- … 17 more at https://npm.io/package/req-error/versions

## README

# 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

<a href="https://npmjs.com/package/req-error">
  <img src="https://img.shields.io/npm/v/req-error" alt="npm package"> 
</a>

---

## Installation

- with npm

```shell
npm i req-error
```

- with yarn

```shell
yarn add req-error
```

- with pnpm

```shell
pnpm add req-error
```

<br/> <br/>

# Express

Configure your application with whatever configuration you want.

## Basic Usage:

`/* controller.js */`

```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')
```

```js
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)
})
```

<br/>

---

<br/>

### Some possible usages of `ReqError`:

```js
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]
```

<br />

### Some possible usages of `catchError`:

```js
// 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 }]
```

<br />


---

Made by [Nazmus Sayad](https://github.com/NazmusSayad) with ❤️.

---
_Source: https://npm.io/package/req-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
