Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@curveball/problem

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@curveball/problem

A middleware for converting errors into application/problem+json

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

Curveball Problem Middleware

Greenkeeper badge

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 @curveball/problem

Getting started

import problemMw from '@curveball/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.

Keywords

FAQs

Package last updated on 13 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc