Ghost/core/shared/sentry.js
Sam Lord 2887e416da
Switch to @tryghost/errors from ignition errors package (#13807)
refs: TryGhost/Toolbox#147

* Replaces all references to isIgnitionError with isGhostError
* Switches use of GhostError to InternalServerError - as GhostError is no longer public
There are places where InternalServerError is not the valid error, and new errors should be added to the @tryghost/errors package to ensure that we can use semantically correct errors in those cases.
2021-12-01 10:22:01 +00:00

43 lines
1.4 KiB
JavaScript

const config = require('./config');
const sentryConfig = config.get('sentry');
const errors = require('@tryghost/errors');
if (sentryConfig && !sentryConfig.disabled) {
const Sentry = require('@sentry/node');
const version = require('../../package.json').version;
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.isGhostError(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 {
const expressNoop = function (req, res, next) {
next();
};
module.exports = {
requestHandler: expressNoop,
errorHandler: expressNoop,
captureException: () => {}
};
}