An HTTP error class throwing with proper status codes
Follow @marcuspoehls and @superchargejs for updates!
The @supercharge/http-errors package provides an HTTP error class with useful defaults.
- provides an
HttpErrorbase class with defaults to throw proper HTTP errors - the
HttpErrorbase class captures stack traces by default - create your own HTTP error with custom HTTP status code, title, and error code
npm i @supercharge/http-errors
Using @supercharge/http-errors is pretty straightforward. The package exports the HttpError class that you can use like the native Error class.
const{ HttpError }=require('@supercharge/http-errors')// create an HTTP 400 BadRequest error yourselfthrownewHttpError('invalid request input data',400)// … or throw using shortcut methodsthrowHttpError.badRequest('Request validation failed')// … or use a fluent interface to customize the propertiesthrownewHttpError('Request validation failed').withStatus(400).withCode('E_YOUR_CUSTOM_ERROR_CODE')Do you miss a function? We very much appreciate your contribution! Please send in a pull request 😊
- Create a fork
- Create your feature branch:
git checkout -b my-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request 🚀
MIT © Supercharge
superchargejs.com · GitHub @supercharge · Twitter @superchargejs