From 147ec911620148ad735a629849907cc9910ae35b Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 9 Aug 2017 18:24:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=20Switched=20to=20404=20error?= =?UTF-8?q?=20in=20image=20size=20utility=20(#8862)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #8850 - This reduces the amount of noise from the image size utility. --- core/server/utils/cached-image-size-from-url.js | 4 ++++ core/server/utils/image-size-from-url.js | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/server/utils/cached-image-size-from-url.js b/core/server/utils/cached-image-size-from-url.js index 107fb9186d..59ed7c5734 100644 --- a/core/server/utils/cached-image-size-from-url.js +++ b/core/server/utils/cached-image-size-from-url.js @@ -1,6 +1,7 @@ var Promise = require('bluebird'), size = require('./image-size-from-url'), logging = require('../logging'), + errors = require('../errors'), getImageSizeFromUrl = size.getImageSizeFromUrl, imageSizeCache = {}; @@ -23,6 +24,9 @@ function getCachedImageSizeFromUrl(url) { imageSizeCache[url] = res; return Promise.resolve(imageSizeCache[url]); + }).catch(errors.NotFoundError, function () { + // in case of error we just attach the url + return Promise.resolve(imageSizeCache[url] = url); }).catch(function (err) { logging.error(err); diff --git a/core/server/utils/image-size-from-url.js b/core/server/utils/image-size-from-url.js index a27b3bd870..caffe01f1d 100644 --- a/core/server/utils/image-size-from-url.js +++ b/core/server/utils/image-size-from-url.js @@ -79,9 +79,16 @@ module.exports.getImageSizeFromUrl = function getImageSizeFromUrl(imagePath) { context: imagePath })); } + } else if (res.statusCode === 404) { + return reject(new errors.NotFoundError({ + message: 'Image not found.', + code: 'IMAGE_SIZE', + statusCode: res.statusCode, + context: imagePath + })); } else { return reject(new errors.InternalServerError({ - message: res.statusCode === 404 ? 'Image not found.' : 'Unknown Request error.', + message: 'Unknown Request error.', code: 'IMAGE_SIZE', statusCode: res.statusCode, context: imagePath