2020-05-27 20:47:53 +03:00
|
|
|
const config = require('./config');
|
2020-01-29 15:09:21 +03:00
|
|
|
const sentryConfig = config.get('sentry');
|
2020-06-01 21:01:51 +03:00
|
|
|
const errors = require('@tryghost/errors');
|
2020-01-29 15:09:21 +03:00
|
|
|
|
|
|
|
if (sentryConfig && !sentryConfig.disabled) {
|
|
|
|
const Sentry = require('@sentry/node');
|
2021-05-17 14:32:46 +03:00
|
|
|
const version = require('../../package.json').version;
|
2020-04-27 21:59:09 +03:00
|
|
|
const environment = config.get('env');
|
2020-01-29 15:09:21 +03:00
|
|
|
Sentry.init({
|
|
|
|
dsn: sentryConfig.dsn,
|
2020-04-27 21:59:09 +03:00
|
|
|
release: 'ghost@' + version,
|
|
|
|
environment: environment
|
2020-01-29 15:09:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
requestHandler: Sentry.Handlers.requestHandler(),
|
|
|
|
errorHandler: Sentry.Handlers.errorHandler({
|
|
|
|
shouldHandleError(error) {
|
2020-06-01 21:01:51 +03:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2020-01-29 15:09:21 +03:00
|
|
|
// Only handle 500 errors for now
|
2020-04-25 22:53:58 +03:00
|
|
|
// This is because the only other 5XX error should be 503, which are deliberate maintenance/boot errors
|
2020-01-29 15:09:21 +03:00
|
|
|
return (error.statusCode === 500);
|
|
|
|
}
|
2020-02-19 01:01:49 +03:00
|
|
|
}),
|
|
|
|
captureException: Sentry.captureException
|
2020-01-29 15:09:21 +03:00
|
|
|
};
|
|
|
|
} else {
|
2020-11-10 14:04:21 +03:00
|
|
|
const expressNoop = function (req, res, next) {
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
|
2020-01-29 15:09:21 +03:00
|
|
|
module.exports = {
|
|
|
|
requestHandler: expressNoop,
|
2020-02-19 01:01:49 +03:00
|
|
|
errorHandler: expressNoop,
|
|
|
|
captureException: () => {}
|
2020-01-29 15:09:21 +03:00
|
|
|
};
|
|
|
|
}
|