From 8c93bdff41d9603a08c0835936a94f47ba7dd0b5 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 29 Nov 2021 09:52:38 +0000 Subject: [PATCH] Removed unnecessary BasicErrorRenderer refs: https://github.com/TryGhost/Ghost/commit/4474ca1a1df67a6b678922c8681cf52fd662e60a refs: https://github.com/TryGhost/Ghost/commit/0799f02e8034283e1097e01c1ebec32b74bdc4a1 The BasicErrorRenderer was created as a fallback for when we needed to not render templates, which is chiefly when we're trying to render a 404 for an image. Using a template puts us at risk of an infinite 404 loop if the missing image is referenced in the 404 template. As of 0799f02e, the HTMLErrorRenderer no longer uses templates - instead we serve a very simple HTML page. This can be used instead of the BasicErrorRenderer, as it results in a properly formatted error. Even when sending responses in plain text, the content type is returned as HTML and therefore having an unformatted error makes no sense - if we really need a non-html format I guess there should be no body at all. --- core/server/web/shared/middleware/error-handler.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/core/server/web/shared/middleware/error-handler.js b/core/server/web/shared/middleware/error-handler.js index 7937af34b1..61c9e61c36 100644 --- a/core/server/web/shared/middleware/error-handler.js +++ b/core/server/web/shared/middleware/error-handler.js @@ -289,10 +289,6 @@ _private.HTMLErrorRenderer = (err, req, res, next) => { // eslint-disable-line n return res.send(createHtmlDocument(res.statusCode, err.stack)); }; -_private.BasicErrorRenderer = (err, req, res, next) => { // eslint-disable-line no-unused-vars - return res.send(res.statusCode + ' ' + err.stack); -}; - errorHandler.resourceNotFound = (req, res, next) => { // TODO, handle unknown resources & methods differently, so that we can also produce // 405 Method Not Allowed @@ -327,9 +323,7 @@ errorHandler.handleHTMLResponse = [ // Handle the error in Sentry sentry.errorHandler, // Render the error using HTML format - _private.HTMLErrorRenderer, - // Fall back to basic if HTML is not explicitly accepted - _private.BasicErrorRenderer + _private.HTMLErrorRenderer ]; errorHandler.handleThemeResponse = [ @@ -340,7 +334,7 @@ errorHandler.handleThemeResponse = [ // Render the error using theme template _private.ThemeErrorRenderer, // Fall back to basic if HTML is not explicitly accepted - _private.BasicErrorRenderer + _private.HTMLErrorRenderer ]; module.exports = errorHandler;