mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Fixed theme error handler (#14363)
no issue Prevents errors from being uploaded to Sentry when a 404 happens in Ghost Admin. At the moment, 404s in Ghost Admin create an ENOENT error in express' static library. Our generic 404 handler at the end will only intercept requests that don't have any errors in the context, so a simple middleware can strip out 404 errors just before we add in our own. The Ghost-specific error that we attach to requests does not get uploaded to Sentry :)
This commit is contained in:
parent
3bd4d0989a
commit
de3a45a805
4 changed files with 18 additions and 8 deletions
|
@ -7,7 +7,7 @@ const config = require('../../../shared/config');
|
|||
const helpers = require('../../services/routing/helpers');
|
||||
|
||||
// @TODO: make this properly shared code
|
||||
const {prepareError} = require('@tryghost/mw-error-handler');
|
||||
const {prepareError, prepareStack} = require('@tryghost/mw-error-handler');
|
||||
|
||||
const messages = {
|
||||
oopsErrorTemplateHasError: 'Oops, seems there is an error in the error template.',
|
||||
|
@ -84,10 +84,12 @@ const themeErrorRenderer = (err, req, res, next) => {
|
|||
};
|
||||
|
||||
module.exports.handleThemeResponse = [
|
||||
// Handle the error in Sentry
|
||||
sentry.errorHandler,
|
||||
// Make sure the error can be served
|
||||
prepareError,
|
||||
// Handle the error in Sentry
|
||||
sentry.errorHandler,
|
||||
// Format the stack for the user
|
||||
prepareStack,
|
||||
// Render the error using theme template
|
||||
themeErrorRenderer
|
||||
];
|
||||
|
|
|
@ -46,6 +46,14 @@ module.exports = function setupAdminApp() {
|
|||
// Finally, routing
|
||||
adminApp.get('*', require('./controller'));
|
||||
|
||||
adminApp.use((err, req, res, next) => {
|
||||
if (err.statusCode && err.statusCode === 404) {
|
||||
// Remove 404 errors for next middleware to inject
|
||||
next();
|
||||
} else {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
adminApp.use(errorHandler.pageNotFound);
|
||||
adminApp.use(errorHandler.handleHTMLResponse(sentry));
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
"@tryghost/members-stripe-service": "0.9.1",
|
||||
"@tryghost/metrics": "1.0.6",
|
||||
"@tryghost/minifier": "0.1.11",
|
||||
"@tryghost/mw-error-handler": "0.1.4",
|
||||
"@tryghost/mw-error-handler": "0.1.5",
|
||||
"@tryghost/mw-session-from-token": "0.1.28",
|
||||
"@tryghost/nodemailer": "0.3.14",
|
||||
"@tryghost/nql": "0.9.0",
|
||||
|
|
|
@ -2229,10 +2229,10 @@
|
|||
dependencies:
|
||||
lodash "^4.17.11"
|
||||
|
||||
"@tryghost/mw-error-handler@0.1.4":
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/@tryghost/mw-error-handler/-/mw-error-handler-0.1.4.tgz#d2a0cd308cdcf034ea6920434b7b8376dd93946d"
|
||||
integrity sha512-hST8JPvYwIsx+YkspuC98B7mpwJ/JxF+RYuMMpLQBAX5cUaTsACy/qAz8iMBokqNAUaeNXMWQwEl4KTkvtj8Fg==
|
||||
"@tryghost/mw-error-handler@0.1.5":
|
||||
version "0.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@tryghost/mw-error-handler/-/mw-error-handler-0.1.5.tgz#e7791c44ba954b19cc91e9ca2f66ef4bc37a6972"
|
||||
integrity sha512-HF0ubWNgOmz47o5+7yuzde40upYf0b/ZveHFO6P0UkLsTdkYhPp5Sj7TCr2TYR2JwuZLt2mTVCBxHRuI4SzlTA==
|
||||
dependencies:
|
||||
"@tryghost/debug" "^0.1.9"
|
||||
"@tryghost/errors" "1.2.5"
|
||||
|
|
Loading…
Add table
Reference in a new issue