npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

Properties

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

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

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

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

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

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

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

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