Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express server middleware function not handling exceptions #2059

Closed
nealalpert opened this issue May 24, 2017 · 2 comments
Closed

Express server middleware function not handling exceptions #2059

nealalpert opened this issue May 24, 2017 · 2 comments

Comments

@nealalpert
Copy link

We implemented some custom error handling on our express server with an error handling middleware function. The idea was to handle exceptions and send error messages and stack traces to a log so we could correct them in a timely fashion.

const express = require('express');
const next = require('next');
const Rollbar = require('rollbar');
const config = require('./env/config');

const rollbar = new Rollbar({
  accessToken: config.SERVER_ERROR_REPORTING_TOKEN,
  handleUncaughtExceptions: true,
  handleUnhandledRejections: true,
  payload: {
    environment: config.APP_ENV,
  },
});
const dev = process.env.MODE !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

app.prepare()
.then(() => {
  const server = express();

  server.get('*', (req, res) => handle(req, res));

  server.use(rollbar.errorHandler());

  server.listen(3000, (err) => {
    if (err) throw err;
    console.log('> Ready on http://localhost: 3000');
  });
});

Problem is the error event emissions seem to be getting captured before express gets ahold of them.

Any idea what might be doing this?

@ethanresnick
Copy link

See #1852. I want this as well!

@arunoda
Copy link
Contributor

arunoda commented May 25, 2017

Thanks @ethanresnick for the reference.
Closing this one in favor of the reference.

@arunoda arunoda closed this as completed May 25, 2017
@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants