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

shiny-express-errors

v1.2.2

Published

Error handling functionality for express/node.js

Downloads

4,909

Readme

Express Error Handler

Formats errors for the api-problem+json media-type

Error details (e.g. name, message, stack) will be included if the showDetails option is set. If the error already has a detail property, that is included as well, either as description if it is a string, or as the included properties if it is an object.

If err.status, err.statusCode or err.output.statusCode is set, that will set the HTTP status for the error response. It will also display the error's message property.

Usage

Include the module

errorHandler = require('shiny-express-errors');

[handleErrors]{#handleErrors} [handleUncaughtErrors]{#handleUncaughtErrors} [sendError]{#sendError} [serializer]{#serializer} [getStatusCode]{#getStatusCode} [getRootError]{#getRootError}


Add middleware for error handling

app.use(errorHandler.handleErrors(options));

options

  • showDetails: boolean|function(err, req). whether to include error details (like stack) in response. Defaults to return true if statusCode is known and less than 500. Suggest changing it to show for all but 500+ in production

  • showStack: boolean|function(err, req). whether to include stack trace in response. Defaults to false. Suggest changing it to show for all but production

  • errorCallback: function(err, req, responseSent). callback to run before sending error response (e.g. custom logging or whatever). responseSent is a boolean, true if response headers have already been sent, i.e. next(err) will not be called, so error is not indicated is response. Defaults to doing nothing

  • describedBy: string|function(req). when string, value will be used in the describedBy field. when function, function will be run to generate field (with req as an argument). Defaults to <host>/errors/error.html


Add middleware for uncaught errors (uses domains). Attempts to send error response if response not already sent. Then it closes any open connections before shutting down the server. Server should be shut down after an uncaught exception: it always indicates a programmer error that should be fixed immediately.

app.use(errorHandler.handleUncaughtErrors(options));

options

  • callback: function(err, req). callback to run before closing

Send an error response to the client. Sends using api-problem media type.

errorHandler.sendError(req, res, status, title, detail)


Bunyan serializer. Includes recursive verror walking serializer = require('shiny-express-errors').serializer;


Inspect Error object to try to determine appropriate http status code

var code = serializer.statusCode(err);

Get root error. Recurses verrors to get original error object

var e = serializer.getRootError(err);