mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
310ecd37c4
no issue - in the near future, non-Ghost Ignition type errors will be coming into Sentry - because they don't have a statusCode, they'll be rejected - we want to detect if they're non-Ghost and still deal with them
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
const config = require('./config');
|
|
const sentryConfig = config.get('sentry');
|
|
const errors = require('@tryghost/errors');
|
|
|
|
const expressNoop = function (req, res, next) {
|
|
next();
|
|
};
|
|
|
|
if (sentryConfig && !sentryConfig.disabled) {
|
|
const Sentry = require('@sentry/node');
|
|
const version = require('../server/lib/ghost-version').full;
|
|
const environment = config.get('env');
|
|
Sentry.init({
|
|
dsn: sentryConfig.dsn,
|
|
release: 'ghost@' + version,
|
|
environment: environment
|
|
});
|
|
|
|
module.exports = {
|
|
requestHandler: Sentry.Handlers.requestHandler(),
|
|
errorHandler: Sentry.Handlers.errorHandler({
|
|
shouldHandleError(error) {
|
|
// Sometimes non-Ghost issues will come into here but they won't
|
|
// have a statusCode so we should always handle them
|
|
if (!errors.utils.isIgnitionError(error)) {
|
|
return true;
|
|
}
|
|
|
|
// Only handle 500 errors for now
|
|
// This is because the only other 5XX error should be 503, which are deliberate maintenance/boot errors
|
|
return (error.statusCode === 500);
|
|
}
|
|
}),
|
|
captureException: Sentry.captureException
|
|
};
|
|
} else {
|
|
module.exports = {
|
|
requestHandler: expressNoop,
|
|
errorHandler: expressNoop,
|
|
captureException: () => {}
|
|
};
|
|
}
|