feat(api): enable Sentry reporting
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
61e5bf942b
commit
10a6622546
19
api-server/server/middlewares/sentry-error-handler.js
Normal file
19
api-server/server/middlewares/sentry-error-handler.js
Normal 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;
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user