tnpom-capture-errors

1.0.1 • Public • Published

tnpom-capture-errors

Documentation

Table of Contents

CaptureErrors

Meta

ApplicationError

Meta

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, default 500)

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

  • status number Override the set req.errorStatus, err.defaultStatusCode
  • message
  • msg string

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

  • next function
  • statusCode number error statusCode, overrides the caught errors "defaultStatus"

Examples

Router.get('/', (req, res,next)=>{
  someAsyncThing()
  .then()
  .catch(CaptureError.capture(next, 401))
}, CaptureError.handle())

Returns Function middleware

Readme

Keywords

none

Package Sidebar

Install

npm i tnpom-capture-errors

Weekly Downloads

0

Version

1.0.1

License

SEE LICENSE IN LICENSE

Unpacked Size

149 kB

Total Files

9

Last publish

Collaborators

  • trivnowllc