Files
freeCodeCamp/api-server/server/middlewares/sentry-error-handler.js

24 lines
818 B
JavaScript
Raw Normal View History

2020-03-23 18:31:25 +01:00
import { Handlers, captureException } from '@sentry/node';
import { sentry } from '../../../config/secrets';
import { isHandledError } from '../utils/create-handled-error';
2020-03-23 18:31:25 +01:00
// sends directly to Sentry
2020-03-23 18:31:25 +01:00
export function reportError(err) {
return sentry.dns === 'dsn_from_sentry_dashboard'
? console.error(err)
: captureException(err);
}
// determines which errors should be reported
2020-03-23 18:31:25 +01:00
export default function sentryErrorHandler() {
return sentry.dns === 'dsn_from_sentry_dashboard'
? (req, res, next) => next()
: Handlers.errorHandler({
shouldHandleError(err) {
// CSRF errors have status 403, consider ignoring them once csurf is
// no longer rejecting people incorrectly.
2020-03-26 17:52:57 +01:00
return !isHandledError(err) && (!err.status || err.status >= 500);
2020-03-23 18:31:25 +01:00
}
});
}