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
, andmessage
is a string to show in the HTTP response body.
Usage
const app = app app // Always add the error handling middleware last!app // Request /ddos// -> 500 - Internal Server Error // Request /whoami// -> 418 - I'm a teapot
See also
- @http2/server An HTTP/2 server using this package.
- http-errors Utility to throw valid HTTP errors.