errdrop
A lightweight drop-in Error
replacement with take-it-or-leave-it HTTP status code support.
Useful for preserving associations between errors and their appropriate HTTP status codes when decoupling application logic from middleware plumbing.
Installation
# npm npm i errdrop # yarn yarn add errdrop
Example
const Error = // Good practice to decouple application logic// from middleware plumbing (req/res) { } app
Supported status codes
Subclasses are generated for each entry in http.STATUS_CODES
. See here for the full list.
These classes pass all arguments through to Error
for full drop-in compatibility.
Custom or nonstandard status codes are supported via the generic Error.StatusCode
class, which prepends the Error
class signature with a status code parameter:
throw 218 'This is fine'
thinware
support
This module pairs well with thinware, which honors status codes attached to thrown Error
objects:
/* /say-hello/Dwight => 403 Forbidden "Go away, Dwight." /say-hello/Michael => 301 Moved Permanently "Moved Permanently" /say-hello/Pam => 200 OK "Hello, Pam!"*/app