Sentry不会捕获nodejs环境中的所有错误
我正在尝试部署一个哨兵安装来捕获我的应用程序中的错误,不知怎的,我真的不明白该怎么做。
我有这个示例应用程序:
const express = require('express');
const app = express();
var Raven = require('raven');
Raven.config('http://[email protected]/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);
});
哨兵完全记录了/
路线上的错误,但没有在/KO
路线上。我想让它记录可能出现在节点控制台中的所有错误,而不使用throw error
。
我怎么做?
回答如下:在所有路线之后放置app.use
线,特别是onError
处理程序。 Node的本机错误处理可能是在Sentry之前捕获它。
const express = require('express');
const app = express();
var Raven = require('raven');
Raven.config('http://[email protected]/7').install();
app.use(Raven.requestHandler());
app.get('/', function mainHandler(req, res) {
throw new Error('Broke!');
});
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);
});
app.use(Raven.errorHandler());
app.use(function onError(err, req, res, next) {
res.statusCode = 500;
res.end(res.sentry + '\n');
});
披露:我在Sentry工作,但我没有维护我们的Node SDK。如果您想要更深入的答案,请在节点仓库中打开一个问题。
Sentry不会捕获nodejs环境中的所有错误
我正在尝试部署一个哨兵安装来捕获我的应用程序中的错误,不知怎的,我真的不明白该怎么做。
我有这个示例应用程序:
const express = require('express');
const app = express();
var Raven = require('raven');
Raven.config('http://[email protected]/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);
});
哨兵完全记录了/
路线上的错误,但没有在/KO
路线上。我想让它记录可能出现在节点控制台中的所有错误,而不使用throw error
。
我怎么做?
回答如下:在所有路线之后放置app.use
线,特别是onError
处理程序。 Node的本机错误处理可能是在Sentry之前捕获它。
const express = require('express');
const app = express();
var Raven = require('raven');
Raven.config('http://[email protected]/7').install();
app.use(Raven.requestHandler());
app.get('/', function mainHandler(req, res) {
throw new Error('Broke!');
});
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);
});
app.use(Raven.errorHandler());
app.use(function onError(err, req, res, next) {
res.statusCode = 500;
res.end(res.sentry + '\n');
});
披露:我在Sentry工作,但我没有维护我们的Node SDK。如果您想要更深入的答案,请在节点仓库中打开一个问题。