【发布时间】:2020-02-02 23:12:44
【问题描述】:
我想将 sentry 与 nest.js + express 集成,但我刚刚找到了 raven 版本,但已弃用。 我按照哨兵文档与 express 集成,但不知道如何处理“所有控制器都应该住在这里”部分。
const express = require('express');
const app = express();
const Sentry = require('@sentry/node');
Sentry.init({ dsn: 'https://5265e36cb9104baf9b3109bb5da9423e@sentry.io/1768434' });
// The request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());
**// All controllers should live here
app.get('/', function rootHandler(req, res) {
res.end('Hello world!');
});**
// The error handler must be before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler());
// Optional fallthrough error handler
app.use(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");
});
app.listen(3000);
【问题讨论】:
-
你的问题不是很清楚,但是对于你提供的代码,除了没有和nest.js集成之外,还有其他问题吗?
-
一切都很好,只是这部分代码是问题 app.get('/', function rootHandler(req, res) { res.end('Hello world!'); });
标签: javascript nestjs