tnpom-capture-errors
v1.0.1
Published
Standardized error handling middleware and utilities.
Downloads
2
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
message
string Error message (optional, default"Application Error"
)status
number (optional, default500
)
Properties
defaultStatusCode
number 500
ResourceRequiredError
Extends exports.ApplicationError
Resource Required - A resource is required to complete the requested action.
Parameters
message
string Error message (optional, default"A resource is required to complete the requested action."
)
Properties
defaultStatusCode
number 400
ResourceNotFoundError
Extends exports.ApplicationError
Resource Not Found - Could not find a requested resource.
Parameters
message
string Error message (optional, default"Could not find a requested resource."
)
Properties
defaultStatusCode
number 404
ResourceLimitedError
Extends exports.ApplicationError
Resource Limited - The maximum number of this resource has been met.
Parameters
message
string Error message (optional, default"The maximum number of this resource has been met."
)
Properties
defaultStatusCode
number 400
ResourceOwnerError
Extends exports.ApplicationError
Resource Owner - This resource can only be Updated by its owner.
Parameters
message
string Error message (optional, default"This resource can only be Updated by its owner."
)
Properties
defaultStatusCode
number 401
ResourceDeleteConstraintError
Extends exports.ApplicationError
Resource Delete Constraint - This resource can not be deleted due to a constraint.
Parameters
message
string Error message (optional, default"This resource can not be deleted due to a constraint."
)
Properties
defaultStatusCode
number 400
ApiTimedOutError
Extends exports.ApplicationError
Api Timed Out - The request to the api server timed out.
Parameters
message
string Error message (optional, default"The request to the api server timed out."
)
Properties
defaultStatusCode
number 400
ParametersRequiredError
Extends exports.ApplicationError
Parameters Required - The request requires additional parameters to continue.
Parameters
message
string Error message (optional, default"The request requires additional parameters to continue"
)
Properties
defaultStatusCode
number 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