Connect整合Sentry
阿新 • • 發佈:2018-11-08
我們的Connect整合只需要安裝@ sentry / node,然後您可以像這樣使用它:
const connect = require('connect'); const Sentry = require('@sentry/node'); // Must configure Sentry before doing anything else with it Sentry.init({ dsn: 'https://<key>@sentry.io/<project>' }); function mainHandler(req, res) { throw new Error('Broke!'); } function onError(err, req, res, next) { // The error id is attached to `res.sentry` to be returned // and optionally displayed to the user for support. res.statusCode = 500; res.end(res.sentry + '\n'); } connect( // The request handler be the first item Sentry.Handlers.requestHandler(), connect.bodyParser(), connect.cookieParser(), mainHandler, // The error handler must be before any other error middleware Sentry.Handlers.errorHandler(), // Optional fallthrough error handler onError ).listen(3000);