Sentry Express error handling middleware doesn't work for me

Viewed 156

I've tried this example from Sentry docs, but instead of catching the exception and reporting it to Sentry, the exception goes unhandled and I get a stack trace from the app's stderr and nothing is registered in Sentry.

The DSN is right (I can send events programmatically) and the option filter out requests from localhost is off.

    import express from 'express';
    import * as Sentry from '@sentry/node';

    Sentry.init({ dsn: process.env.SENTRY_DSN });
    const webServer = express();
    webServer.use(Sentry.Handlers.requestHandler());
    webServer.get('/forceError', (req) => {
      throw new Error('Exception thrown');
    });
    webServer.use(Sentry.Handlers.errorHandler());
    webServer.listen(80, () => console.log('http on :80'));
0 Answers
Related