Error handler for use in development (debug) and production environments.
Go to file
David Cheung 57343bba20 Merge pull request #12 from strongloop/array-no-status-code
Remove statusCode from details in Array errors
2016-05-25 13:51:08 -04:00
lib Remove statusCode from details in Array errors 2016-05-25 11:12:31 -04:00
test Remove statusCode from details in Array errors 2016-05-25 11:12:31 -04:00
.eslintrc Add project infrastructure 2016-05-13 12:58:28 +02:00
.gitignore Initial commit 2016-01-22 09:08:22 -08:00
.travis.yml Add project infrastructure 2016-05-13 12:58:28 +02:00
CHANGES.md 1.0.0 2016-05-20 17:36:57 +02:00
LICENSE.md Add project infrastructure 2016-05-13 12:58:28 +02:00
README.md Initial implementation 2016-05-13 13:10:53 +02:00
package.json Initial implementation 2016-05-13 13:10:53 +02:00

README.md

strong-error-handler

Error handler for use in development (debug) and production environments.

  • When run in production mode, error responses are purposely undetailed in order to prevent leaking sensitive information.

  • When in debug mode, detailed information such as stack traces are returned in the HTTP responses.

JSON is the only supported response format at this time.

There are plans to support other formats such as Text, HTML, and XML.

Install

$ npm install strong-error-handler

Usage

In an express-based application:

var express = require('express');
var errorHandler = require('strong-error-handler');

var app = express();
// setup your routes
app.use(errorHandler({ /* options, see below */ }));

app.listen(3000);

In LoopBack applications, add the following entry to your server/middleware.json file.

{
  "final:after": {
    "strong-error-handler": {
      "params": {
       }
    }
  }
}

Options

debug

boolean, defaults to false.

When enabled, HTTP responses include all error properties, including sensitive data such as file paths, URLs and stack traces.

log

boolean, defaults to true.

When enabled, all errors are printed via console.error.

Customization of the log format is intentionally not allowed. If you would like to use a different format/logger, disable this option and add your own custom error-handling middleware.

app.use(myErrorLogger());
app.use(errorHandler({ log: false }));