Socket
Socket
Sign inDemoInstall

@dotcom-reliability-kit/middleware-render-error-info

Package Overview
Dependencies
40
Maintainers
5
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dotcom-reliability-kit/middleware-render-error-info

Express middleware to render error information in a way that makes local debugging easier and production error rendering more consistent.


Version published
Maintainers
5
Created

Readme

Source

@dotcom-reliability-kit/middleware-render-error-info

Express middleware to render error information in a browser in a way that makes local debugging easier and production error rendering more consistent. This module is part of FT.com Reliability Kit.

Usage

Install @dotcom-reliability-kit/middleware-render-error-info as a dependency:

npm install --save @dotcom-reliability-kit/middleware-render-error-info

Include in your code:

import renderErrorInfoPage from '@dotcom-reliability-kit/middleware-render-error-info';
// or
const renderErrorInfoPage = require('@dotcom-reliability-kit/middleware-render-error-info');

renderErrorInfoPage

The renderErrorInfoPage function can be used to generate Express middleware which renders an error debugging page in local development and a sensible stripped-back error page in production.

When the NODE_ENV environment variable is either empty or set to "development" then a full debug page will be rendered. Otherwise only the error status code and message will be output, e.g. 500 Server Error. This ensures that we don't leak important error information in production.

[!CAUTION]
This middleware must be added to your Express app after all your application routes – you won't get rendered errors for any routes which are mounted after this middleware.

const app = express();
// App routes go here
app.use(renderErrorInfoPage());

[!CAUTION]
If you're using @dotcom-reliability-kit/middleware-log-errors in your app, it's best to mount the error page middleware after the logging middleware. Otherwise the error will never be logged.

Once you've mounted the middleware, if you're working locally you should now see a detailed error page when you encounter an error in your app (assuming you're relying on the Express error handler to serve errors):

Reliability Kit Error Info Page

Debug headers

As well as rendering an error page, the middleware also sends an error-fingerprint HTTP header in the response. This contains the error fingerprint and is available in development and production. Inspecting this header on a generic error page can help identify the root cause of an issue.

Migrating

Consult the Migration Guide if you're trying to migrate to a later major version of this package.

Contributing

See the central contributing guide for Reliability Kit.

License

Licensed under the MIT license.
Copyright © 2022, The Financial Times Ltd.

FAQs

Last updated on 10 May 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc