Return empty request and error handlers

In case Sentry is not set up, empty request and error handler functions
are returned instead of nulls.
This commit is contained in:
Hannu Lyytikainen 2017-09-26 15:29:36 +03:00
parent 1882e25d00
commit d46e4cdfc5
2 changed files with 7 additions and 4 deletions

View file

@ -162,7 +162,7 @@ app.get('*', (req, res) => {
});
// Set error handler. If Sentry is set up, all error responses
// (500 and up) will be logged there.
// will be logged there.
app.use(log.errorHandler());
app.listen(PORT, () => {

View file

@ -34,7 +34,9 @@ exports.requestHandler = () => {
if (SENTRY_DSN) {
return Raven.requestHandler();
} else {
return null;
return (req, res, next) => {
next();
};
}
};
@ -46,7 +48,9 @@ exports.errorHandler = () => {
if (SENTRY_DSN) {
return Raven.errorHandler();
} else {
return null;
return (err, req, res, next) => {
next(err);
};
}
};
@ -60,7 +64,6 @@ exports.errorHandler = () => {
*/
exports.error = (e, data) => {
if (SENTRY_DSN) {
console.log('logging an exception');
Raven.captureException(e, { extra: data });
} else {
console.error(e);