http-errors-promise
Server side error handling service, best suited for promise chains, uses http-errors
.
Basic Usage
const error = ; router
Shining Use-case
{ // returns a promise return { // doing some stuff... if someCondition ; else return ; }} { // calls 'doSomething', does its own processing and returns a promise return ;} { }
Methods
error(err, secErr, status = 500, dontReject)
err
error object recieved from a function callsecErr
error from the current contextstatus
http status, defaults to 500- returns a rejected promise with the resulting error
dontReject
returns the resulting error instead of a rejected promise
error.respond(res, err, secErr, status = 500)
- similar to
error
method, except that it takes the express' response object and sends the response with the error instead of returning
error.make(err, status = 500)
- creates and returns an error using
http-errors
makeCommonErrors(modelName)
- creates and returns commonly seen errors by using a dynamically set
modelName
in the error message, also usinghttp-errors
- the common errors are defined in
common.js
(you're welcome to add new errors there)
Design inspired by ralusek's work on error handling