🎨 Switched to 404 error in image size utility (#8862)

refs #8850

- This reduces the amount of noise from the image size utility.
This commit is contained in:
Hannah Wolfe 2017-08-09 18:24:28 +01:00 committed by Katharina Irrgang
parent f554523d23
commit 147ec91162
2 changed files with 12 additions and 1 deletions

View File

@ -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);

View File

@ -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