2017-12-15 4 views
1

私のアプリでエラーをキャッチするためにセントリインストールを配備しようとしていますが、何とかそれを行う方法が分かりません。完全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を使わずにノードコンソールに表示される可能性のあるすべてのエラーを記録するようにします。

どうすればよいですか?

答えて

0

すべてのルートの後にapp.use行、特にonErrorハンドラを配置します。ノードのネイティブエラー処理がSentry'sの前にそれをキャッチしているかもしれません。

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は維持していません。より詳細な回答が必要な場合は、ノードレポで問題を開いてください。

関連する問題