项目作者: matthisk

项目描述 :
🤖 Node JS Middelware capturing & rendering improved stack traces
高级语言: JavaScript
项目地址: git://github.com/matthisk/debug-error-middleware.git
创建时间: 2017-08-13T18:22:16Z
项目社区:https://github.com/matthisk/debug-error-middleware

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Express/Koa error handling middleware

Build Status

Better context information for NodeJS Errors during development. The middleware
parses potential errors that occur during a request/response cycle and display
the stack trace plus additional context in the response.

Features:

  • Stack traces + collapsable code (snippets)
  • Sourcemaps
  • Environment variables
  • Request information

Example Page

Currently we support these two HTTP frameworks:

  • Express
  • Koa

Setup

  1. $ npm install debug-error-middleware

Never enable the DEBUG middleware in a production environment. This could result
in leaking sensitive information (e.g. ENV variables). The middleware throws an
error if you try to load it with NODE_ENV set to "production".

Express

The debug middleware should be loaded first so we can catch errors from all
other middleware.

  1. var debugMiddleware = require('debug-error-middleware').express;
  2. var app = express();
  3. if (process.env.NODE_ENV === 'development') {
  4. app.use(debugMiddleware());
  5. }

Koa

  1. var debugMiddleware = require('debug-error-middleware').koa;
  2. var app = new Koa();
  3. if (process.env.NODE_ENV === 'development') {
  4. app.use(debugMiddleware());
  5. }

Source Map Support

Even though it is not desirable to run transpiled source code inside the
node js runtime, you often do not escape the use of it because of Server Side
Rendering applications. debug-error-middleware automatically supports sourcemaps.
This will result in stack traces that are easier to interpret. You can disable
source map support through a configuration option.

Configuration

The following configuration options are available:

  1. {
  2. theme: 'okaidia', // The prismjs theme to use
  3. disabledForXHR: true // Disable the middleware for XHR requests
  4. disableSourceMapSupport: false // Disables support for sourcemaps
  5. }