Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brunocarvalhodearaujo/error-handler

A error handler for express APIs applications.
https://github.com/brunocarvalhodearaujo/error-handler

Last synced: 9 days ago
JSON representation

A error handler for express APIs applications.

Awesome Lists containing this project

README

        

error-handler
=============

A error handler for express APIs applications.

## Installation

```sh
$ npm install --save @brunocarvalho/error-handler
```

## usage

```ts
import express from 'express'
import errorHandler, { type RequestError } from '@brunocarvalho/error-handler'

const app = express()

app.get('/', (req, res) => {
const err: RequestError = new Error('Not Found')
err.reason = `item not found in database`
err.statusCode = 404
throw err
})

app.use(errorHandler())
```