【发布时间】:2018-05-29 22:28:24
【问题描述】:
我正在尝试部署一个哨兵安装来捕获我的应用程序中的错误,但不知何故我真的不明白如何做到这一点。
我有这个示例应用程序:
const express = require('express');
const app = express();
var Raven = require('raven');
Raven.config('http://6c4b87dasdasdf3ecca9@logs.ekaf.com/7').install();
app.use(Raven.requestHandler());
app.get('/', function mainHandler(req, res) {
throw new Error('Broke!');
});
app.use(Raven.errorHandler());
app.use(function onError(err, req, res, next) {
res.statusCode = 500;
res.end(res.sentry + '\n');
});
const PORT = process.env.PORT || 443;
app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});
app.get('/OK', (req, res, next) => {
res.send('route OK');
});
app.get('/KO', (req, res, next) => {
res.send(blabla);
});
Sentry 完美地记录了/ 路由上的错误,但没有记录/KO 路由上的错误。我想让它记录节点控制台中可能出现的所有错误,而不使用throw error。
我该怎么做?
【问题讨论】: