feat(api): enable Sentry reporting

This commit is contained in:
Oliver Eyton-Williams
2020-03-23 18:31:25 +01:00
committed by Mrugesh Mohapatra
parent 61e5bf942b
commit 10a6622546
7 changed files with 47 additions and 7 deletions

View File

@ -0,0 +1,19 @@
import { Handlers, captureException } from '@sentry/node';
import { sentry } from '../../../config/secrets';
export function reportError(err) {
return sentry.dns === 'dsn_from_sentry_dashboard'
? console.error(err)
: captureException(err);
}
export default function sentryErrorHandler() {
return sentry.dns === 'dsn_from_sentry_dashboard'
? (req, res, next) => next()
: Handlers.errorHandler({
shouldHandleError(error) {
// NOTE: 400 is too low, this is just for debugging
return !error.status || error.status >= 400;
}
});
}