# express-error-bouncer

> A central error handler for express

Latest version **1.0.1** (published 2019-07-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install express-error-bouncer
pnpm add express-error-bouncer
yarn add express-error-bouncer
bun add express-error-bouncer
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-07-19 |
| First published | 2019-07-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chinedu Orie |
| Maintainers | oriechinedu |
| Keywords | Express, NodeJs, Error, Middleware |

## Links

- npm: https://www.npmjs.com/package/express-error-bouncer
- Repository: https://github.com/oriechinedu/express-error-bouncer
- Homepage: https://github.com/oriechinedu/express-error-bouncer#readme
- Issues: https://github.com/oriechinedu/express-error-bouncer/issues
- npm.io page: https://npm.io/package/express-error-bouncer

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-07-19
- 1.0.0 — 2019-07-18

## README

## A Central error handler for express app
Express error bouncer is a middleware that abstracts the handling of HTTP errors in an express application. It eliminates the need to return error response for every checkpoint in the application by using the express error-handling middleware.

## Usage

- npm install `express-error-bouncer`
- In your express server file, require `bouncer`

```javascript
const { bouncer } = require('express-error-bouncer');

const express = require('express')

const app = express()

app.use(express.json())
const PORT = process.env.PORT || 300
  //...
  //...
  //...
app.use(bouncer);
app.listen(PORT, () => console.log(`server listening at port ${PORT}`))

```

- Notice that the bouncer is last in the pipeline, that is, it should be the last before app.listen() call.

Now anywhere in the app that you want to catch error, you can use the `ErrorHandler constructor as shown below:

```js
const { ErrorHandler } = require('express-error-bouncer')

const testBouncer = (req, res, next) => {
  try {
    //
    throw new ErrorHandler(404, 'Resource not found')
  } catch(err){
    next(err)
  }
}
```

The above would return:
```json
{
    "status": "error",
    "code": 404,
    "message": "Resource not found"
}

```

# Contribution
- Got an idea on how to make this package better, feel free to contribute
  
Follow me on twitter [@iam_nedsoft](https://twitter.com/iam_nedsoft) for more updates

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