mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
🎨 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:
parent
f554523d23
commit
147ec91162
2 changed files with 12 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
var Promise = require('bluebird'),
|
var Promise = require('bluebird'),
|
||||||
size = require('./image-size-from-url'),
|
size = require('./image-size-from-url'),
|
||||||
logging = require('../logging'),
|
logging = require('../logging'),
|
||||||
|
errors = require('../errors'),
|
||||||
getImageSizeFromUrl = size.getImageSizeFromUrl,
|
getImageSizeFromUrl = size.getImageSizeFromUrl,
|
||||||
imageSizeCache = {};
|
imageSizeCache = {};
|
||||||
|
|
||||||
|
@ -23,6 +24,9 @@ function getCachedImageSizeFromUrl(url) {
|
||||||
imageSizeCache[url] = res;
|
imageSizeCache[url] = res;
|
||||||
|
|
||||||
return Promise.resolve(imageSizeCache[url]);
|
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) {
|
}).catch(function (err) {
|
||||||
logging.error(err);
|
logging.error(err);
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,16 @@ module.exports.getImageSizeFromUrl = function getImageSizeFromUrl(imagePath) {
|
||||||
context: 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 {
|
} else {
|
||||||
return reject(new errors.InternalServerError({
|
return reject(new errors.InternalServerError({
|
||||||
message: res.statusCode === 404 ? 'Image not found.' : 'Unknown Request error.',
|
message: 'Unknown Request error.',
|
||||||
code: 'IMAGE_SIZE',
|
code: 'IMAGE_SIZE',
|
||||||
statusCode: res.statusCode,
|
statusCode: res.statusCode,
|
||||||
context: imagePath
|
context: imagePath
|
||||||
|
|
Loading…
Add table
Reference in a new issue