From cdb3b0331132397f41758e48810ea8cf6bebe77c Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 24 Jul 2019 17:41:55 +0100 Subject: [PATCH] Updated yaml parser error to be InvalidUsageError - a yaml parser error can only be fixed by the user uploading a file, therefore it should be a 4xx, not a 5xx error - an amp parser error indicates the amperize module is unable to handle a genuine case, and needs to be fixed at the code level --- core/frontend/apps/amp/lib/helpers/amp_content.js | 4 +++- core/frontend/services/settings/yaml-parser.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/frontend/apps/amp/lib/helpers/amp_content.js b/core/frontend/apps/amp/lib/helpers/amp_content.js index ba7f979fc6..b8b1fe71e4 100644 --- a/core/frontend/apps/amp/lib/helpers/amp_content.js +++ b/core/frontend/apps/amp/lib/helpers/amp_content.js @@ -133,14 +133,16 @@ function getAmperizeHTML(html, post) { if (err) { if (err.src) { + // This is a valid 500 GhostError because it means the amperize parser is unable to handle some Ghost HTML. logging.error(new errors.GhostError({ message: `AMP HTML couldn't get parsed: ${err.src}`, + code: 'AMP_PARSER_ERROR', err: err, context: post.url, help: i18n.t('errors.apps.appWillNotBeLoaded.help') })); } else { - logging.error(new errors.GhostError({err})); + logging.error(new errors.GhostError({err, code: 'AMP_PARSER_ERROR'})); } // save it in cache to prevent multiple calls to Amperize until diff --git a/core/frontend/services/settings/yaml-parser.js b/core/frontend/services/settings/yaml-parser.js index 59b32b1bdb..b032e56f4b 100644 --- a/core/frontend/services/settings/yaml-parser.js +++ b/core/frontend/services/settings/yaml-parser.js @@ -18,8 +18,10 @@ module.exports = function parseYaml(file, fileName) { } catch (error) { // CASE: parsing failed, `js-yaml` tells us exactly what and where in the // `reason` property as well as in the message. - throw new common.errors.GhostError({ + // As the file uploaded is invalid, the person uploading must fix this - it's a 4xx error + throw new common.errors.IncorrectUsageError({ message: common.i18n.t('errors.services.settings.yaml.error', {file: fileName, context: error.reason}), + code: 'YAML_PARSER_ERROR', context: error.message, err: error, help: common.i18n.t('errors.services.settings.yaml.help', {file: fileName})