tnpom-capture-errors
v1.0.1
Published
Standardized error handling middleware and utilities.
Readme
tnpom-capture-errors
Documentation
Table of Contents
CaptureErrors
Meta
- author: Jim Bulkowski <[email protected]>
- license: MIT {@link http://opensource.org/licenses/MIT}
ApplicationError
Meta
- author: Jim Bulkowski <[email protected]>
- license: MIT {@link http://opensource.org/licenses/MIT}
ApplicationErrors
ApplicationError
Extends Error
Application Error - Generalized Error. Extend if more than the errors below are needed.
Parameters
messagestring Error message (optional, default"Application Error")statusnumber (optional, default500)
Properties
defaultStatusCodenumber 500
ResourceRequiredError
Extends exports.ApplicationError
Resource Required - A resource is required to complete the requested action.
Parameters
messagestring Error message (optional, default"A resource is required to complete the requested action.")
Properties
defaultStatusCodenumber 400
ResourceNotFoundError
Extends exports.ApplicationError
Resource Not Found - Could not find a requested resource.
Parameters
messagestring Error message (optional, default"Could not find a requested resource.")
Properties
defaultStatusCodenumber 404
ResourceLimitedError
Extends exports.ApplicationError
Resource Limited - The maximum number of this resource has been met.
Parameters
messagestring Error message (optional, default"The maximum number of this resource has been met.")
Properties
defaultStatusCodenumber 400
ResourceOwnerError
Extends exports.ApplicationError
Resource Owner - This resource can only be Updated by its owner.
Parameters
messagestring Error message (optional, default"This resource can only be Updated by its owner.")
Properties
defaultStatusCodenumber 401
ResourceDeleteConstraintError
Extends exports.ApplicationError
Resource Delete Constraint - This resource can not be deleted due to a constraint.
Parameters
messagestring Error message (optional, default"This resource can not be deleted due to a constraint.")
Properties
defaultStatusCodenumber 400
ApiTimedOutError
Extends exports.ApplicationError
Api Timed Out - The request to the api server timed out.
Parameters
messagestring Error message (optional, default"The request to the api server timed out.")
Properties
defaultStatusCodenumber 400
ParametersRequiredError
Extends exports.ApplicationError
Parameters Required - The request requires additional parameters to continue.
Parameters
messagestring Error message (optional, default"The request requires additional parameters to continue")
Properties
defaultStatusCodenumber 400
CaptureError
Type: {handle: handle, capture: capture}
handle
Error handling middleware, Sends data to ElasticSearch via ElasticLogger
Parameters
Examples
Router.get('/', (req, res,next)=>{
someAsyncThing()
.then((result) => {
//set a status code, this will override the default status code if present
// On the error.
req.errorStatus = 401
return next(new Errors.ResourceLimitedError('Too many things'))
})
.catch(CaptureError.capture(next))
}, CaptureError.handle(500, 'Override message')) // The 500 here will override all previous.Returns Function middleware
capture
Capture an error and wrap it with
Parameters
Examples
Router.get('/', (req, res,next)=>{
someAsyncThing()
.then()
.catch(CaptureError.capture(next, 401))
}, CaptureError.handle())Returns Function middleware
