2.1.2 • Published 7 years ago

middleware-plain-error-handler v2.1.2

Weekly downloads
17
License
ISC
Repository
gitlab
Last release
7 years ago

middleware-plain-error-handler

Plain error reporting for Connect and Express with as little magic as possible.

Why?

Unlike the built-in error handler, this package:

  • Does not reveal source code, stack traces, and line numbers.
  • Reliably works the same way whether app is in "production" or "development" mode.
  • Is careful enough to avoid warnings when using HTTP/2.

Error Support

Accepts either HttpError instances, generic Error instances, or any object implementing a {status, message} interface.

  • status is a number >=400 and <600, and
  • message is a string to show in the HTTP response body.

Usage

import {errorHandler} from 'middleware-plain-error-handler'
import createError from 'http-errors'
import express from 'express'

const app = express()

app.get('/ddos', (req, res, next) => {
  next(new Error())
})

app.get('/whoami', (req, res, next) => {
  next(createError(418))
})

// Always add the error handling middleware last!
app.use(errorHandler())

// Request /ddos
// -> 500 - Internal Server Error

// Request /whoami
// -> 418 - I'm a teapot

See also

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago