From d87fbeca4997c6c1429809fd7c8a2ab71f7d7392 Mon Sep 17 00:00:00 2001 From: Katharina Irrgang Date: Tue, 28 Nov 2017 13:00:43 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Fixed=20error=20handling=20fo?= =?UTF-8?q?r=20html=20response=20(#9280)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Team/issues/41 - if you add invalid handlebars logic e.g. {{if condition condition}}, handlebars throws an error - in case of having invalid hbs in an amp page, the amp component throwed another syntax error (which is fixed in this PR) - furthermore the `setTemplate` helper function had a logic bug, which did not handle errors correctly - if there is an error and a template is set (e.g. amp), we have to still render the error page and not the amp page - this fix only ensures that the error handling is correct, we still see the error of the "ugly" handlebars message - e.g. [amp.hbs] Cannot read property 'includeZero' of undefined - but no longer -> Cannot read property 'html' of undefined (which was a syntax error in Ghost) --- core/server/apps/amp/lib/helpers/amp_components.js | 2 +- core/server/controllers/frontend/templates.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/server/apps/amp/lib/helpers/amp_components.js b/core/server/apps/amp/lib/helpers/amp_components.js index 19fc43bd31..34f40406ce 100644 --- a/core/server/apps/amp/lib/helpers/amp_components.js +++ b/core/server/apps/amp/lib/helpers/amp_components.js @@ -13,7 +13,7 @@ var proxy = require('../../../../helpers/proxy'), function ampComponents() { var components = [], - html = this.post.html || this.html; + html = this.post && this.post.html || this.html; if (!html) { return; diff --git a/core/server/controllers/frontend/templates.js b/core/server/controllers/frontend/templates.js index 4c6407057d..4566ff9a50 100644 --- a/core/server/controllers/frontend/templates.js +++ b/core/server/controllers/frontend/templates.js @@ -143,7 +143,7 @@ _private.getTemplateForError = function getTemplateForError(statusCode) { module.exports.setTemplate = function setTemplate(req, res, data) { var routeConfig = res._route || {}; - if (res._template) { + if (res._template && !req.err) { return; }