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

@ocalan/problem

v0.3.1

Published

A middleware for converting errors into application/problem+json

Downloads

3

Readme

Curveball Problem Middleware

NOTE: Published with updated typings, forked from the original module. This version will deprecate once merged.


This package is a middleware for the Curveball framework that catches any exception and turns them into application/problem+json responses, as defined in RFC7807.

By default any exception turns into a non-descript 500 Internal Server Error. To create a more specific error, use an exception from the @curveball/http-errors package or implement one of the interfaces.

Installation

npm install @ocalan/problem

Getting started

import problemMw from '@ocalan/problem';
import { Application } from '@curveball/core';

const app = new Application();
app.use(problemMw());

Typically you will want the problem middleware to be one of the first middlewares you add to the server. Only exceptions from midddlewares that come after the problem middleware can be caught.

Throwing errors

You can throw the following kinds of errors.

  • Standard errors. These errors will be anonimized and logged to the console. a http 500 error gets emitted. (unless debug mode is on).
  • Errors with a httpStatus property. Any error that's thrown that has a httpStatus property will automatically use that http status. The error message will be used as a title.
  • An error from the http-errors package.

Debug mode

By default the middleware will emit a detailed error for any exception that implements the http-errors interfaces, because the assumption is that if these errors were emitted, they were intended for the user of the server.

Any exceptions that are thrown that don't implement these interfaces are stripped from their message and detail and converted to a 500 error to avoid potential security issues.

It's possible to turn this off during development in two ways. You can set the debug setting to true as such:

app.use(problemMw({
  debug: true
});

The second way is by setting the environemnt variable NODE_ENV to the string development.

If the debug property is set, that value always takes precedent.

Quiet mode

If quiet mode is enabled, 4XX errors are not logged. Client errors are common and usually expected behavior, so it might be preferable for them to not spam the log.

app.use(problemMw({
  quiet: true
});