mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Update errors across lib/image and lib/request
- swap common.errors for @tryghost/errors - doing this in batches across small parts of the codebase to reduce disruption
This commit is contained in:
parent
72db5a67ca
commit
10ee38683d
7 changed files with 31 additions and 28 deletions
|
@ -3,7 +3,8 @@ var sizeOf = require('image-size'),
|
|||
_ = require('lodash'),
|
||||
path = require('path'),
|
||||
config = require('../../config'),
|
||||
common = require('../common'),
|
||||
{i18n} = require('../common'),
|
||||
errors = require('@tryghost/errors'),
|
||||
urlUtils = require('../../lib/url-utils'),
|
||||
settingsCache = require('../../services/settings/cache'),
|
||||
storageUtils = require('../../adapters/storage/utils'),
|
||||
|
@ -41,8 +42,8 @@ getIconDimensions = function getIconDimensions(path) {
|
|||
height: dimensions.height
|
||||
});
|
||||
} catch (err) {
|
||||
return reject(new common.errors.ValidationError({
|
||||
message: common.i18n.t('errors.utils.blogIcon.error', {
|
||||
return reject(new errors.ValidationError({
|
||||
message: i18n.t('errors.utils.blogIcon.error', {
|
||||
file: path,
|
||||
error: err.message
|
||||
})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var debug = require('ghost-ignition').debug('utils:image-size-cache'),
|
||||
imageSize = require('./image-size'),
|
||||
common = require('../common'),
|
||||
errors = require('@tryghost/errors'),
|
||||
{logging} = require('../common'),
|
||||
cache = {};
|
||||
|
||||
/**
|
||||
|
@ -24,7 +25,7 @@ function getCachedImageSizeFromUrl(url) {
|
|||
debug('Cached image:', url);
|
||||
|
||||
return cache[url];
|
||||
}).catch(common.errors.NotFoundError, function () {
|
||||
}).catch(errors.NotFoundError, function () {
|
||||
debug('Cached image (not found):', url);
|
||||
// in case of error we just attach the url
|
||||
cache[url] = url;
|
||||
|
@ -32,7 +33,7 @@ function getCachedImageSizeFromUrl(url) {
|
|||
return cache[url];
|
||||
}).catch(function (err) {
|
||||
debug('Cached image (error):', url);
|
||||
common.logging.error(err);
|
||||
logging.error(err);
|
||||
|
||||
// in case of error we just attach the url
|
||||
cache[url] = url;
|
||||
|
|
|
@ -6,7 +6,8 @@ const Promise = require('bluebird');
|
|||
const _ = require('lodash');
|
||||
const request = require('../request');
|
||||
const urlUtils = require('../../lib/url-utils');
|
||||
const common = require('../common');
|
||||
const {i18n} = require('../common');
|
||||
const errors = require('@tryghost/errors');
|
||||
const config = require('../../config');
|
||||
const storage = require('../../adapters/storage');
|
||||
const storageUtils = require('../../adapters/storage/utils');
|
||||
|
@ -54,7 +55,7 @@ function _probeImageSizeFromUrl(url) {
|
|||
// probe-image-size uses `request` npm module which doesn't have our `got`
|
||||
// override with custom URL validation so it needs duplicating here
|
||||
if (_.isEmpty(url) || !validator.isURL(url)) {
|
||||
return Promise.reject(new common.errors.InternalServerError({
|
||||
return Promise.reject(new errors.InternalServerError({
|
||||
message: 'URL empty or invalid.',
|
||||
code: 'URL_MISSING_INVALID',
|
||||
context: url
|
||||
|
@ -147,32 +148,32 @@ const getImageSizeFromUrl = (imagePath) => {
|
|||
height: dimensions.height
|
||||
};
|
||||
}).catch({code: 'URL_MISSING_INVALID'}, (err) => {
|
||||
return Promise.reject(new common.errors.InternalServerError({
|
||||
return Promise.reject(new errors.InternalServerError({
|
||||
message: err.message,
|
||||
code: 'IMAGE_SIZE_URL',
|
||||
statusCode: err.statusCode,
|
||||
context: err.url || imagePath
|
||||
}));
|
||||
}).catch({code: 'ETIMEDOUT'}, {statusCode: 408}, (err) => {
|
||||
return Promise.reject(new common.errors.InternalServerError({
|
||||
return Promise.reject(new errors.InternalServerError({
|
||||
message: 'Request timed out.',
|
||||
code: 'IMAGE_SIZE_URL',
|
||||
statusCode: err.statusCode,
|
||||
context: err.url || imagePath
|
||||
}));
|
||||
}).catch({code: 'ENOENT'}, {statusCode: 404}, (err) => {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: 'Image not found.',
|
||||
code: 'IMAGE_SIZE_URL',
|
||||
statusCode: err.statusCode,
|
||||
context: err.url || imagePath
|
||||
}));
|
||||
}).catch(function (err) {
|
||||
if (common.errors.utils.isIgnitionError(err)) {
|
||||
if (errors.utils.isIgnitionError(err)) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
|
||||
return Promise.reject(new common.errors.InternalServerError({
|
||||
return Promise.reject(new errors.InternalServerError({
|
||||
message: 'Unknown Request error.',
|
||||
code: 'IMAGE_SIZE_URL',
|
||||
statusCode: err.statusCode,
|
||||
|
@ -221,7 +222,7 @@ const getImageSizeFromStoragePath = (imagePath) => {
|
|||
};
|
||||
})
|
||||
.catch({code: 'ENOENT'}, (err) => {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: err.message,
|
||||
code: 'IMAGE_SIZE_STORAGE',
|
||||
err: err,
|
||||
|
@ -232,11 +233,11 @@ const getImageSizeFromStoragePath = (imagePath) => {
|
|||
}
|
||||
}));
|
||||
}).catch((err) => {
|
||||
if (common.errors.utils.isIgnitionError(err)) {
|
||||
if (errors.utils.isIgnitionError(err)) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
|
||||
return Promise.reject(new common.errors.InternalServerError({
|
||||
return Promise.reject(new errors.InternalServerError({
|
||||
message: err.message,
|
||||
code: 'IMAGE_SIZE_STORAGE',
|
||||
err: err,
|
||||
|
@ -279,8 +280,8 @@ const getImageSizeFromPath = (path) => {
|
|||
height: dimensions.height
|
||||
});
|
||||
} catch (err) {
|
||||
return reject(new common.errors.ValidationError({
|
||||
message: common.i18n.t('errors.utils.images.invalidDimensions', {
|
||||
return reject(new errors.ValidationError({
|
||||
message: i18n.t('errors.utils.images.invalidDimensions', {
|
||||
file: path,
|
||||
error: err.message
|
||||
})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const Promise = require('bluebird');
|
||||
const common = require('../common');
|
||||
const errors = require('@tryghost/errors');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
/**
|
||||
|
@ -46,14 +46,14 @@ const makeSafe = fn => (...args) => {
|
|||
try {
|
||||
require('sharp');
|
||||
} catch (err) {
|
||||
return Promise.reject(new common.errors.InternalServerError({
|
||||
return Promise.reject(new errors.InternalServerError({
|
||||
message: 'Sharp wasn\'t installed',
|
||||
code: 'SHARP_INSTALLATION',
|
||||
err: err
|
||||
}));
|
||||
}
|
||||
return fn(...args).catch((err) => {
|
||||
throw new common.errors.InternalServerError({
|
||||
throw new errors.InternalServerError({
|
||||
message: 'Unable to manipulate image.',
|
||||
err: err,
|
||||
code: 'IMAGE_PROCESSING'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var got = require('got'),
|
||||
_ = require('lodash'),
|
||||
validator = require('../data/validation').validator,
|
||||
common = require('./common'),
|
||||
errors = require('@tryghost/errors'),
|
||||
ghostVersion = require('./ghost-version');
|
||||
|
||||
var defaultOptions = {
|
||||
|
@ -12,7 +12,7 @@ var defaultOptions = {
|
|||
|
||||
module.exports = function request(url, options) {
|
||||
if (_.isEmpty(url) || !validator.isURL(url)) {
|
||||
return Promise.reject(new common.errors.InternalServerError({
|
||||
return Promise.reject(new errors.InternalServerError({
|
||||
message: 'URL empty or invalid.',
|
||||
code: 'URL_MISSING_INVALID',
|
||||
context: url
|
||||
|
|
|
@ -5,7 +5,7 @@ const should = require('should'),
|
|||
path = require('path'),
|
||||
configUtils = require('../../../utils/configUtils'),
|
||||
urlUtils = require('../../../../server/lib/url-utils'),
|
||||
common = require('../../../../server/lib/common'),
|
||||
errors = require('@tryghost/errors'),
|
||||
storage = require('../../../../server/adapters/storage');
|
||||
|
||||
describe('lib/image: image size', function () {
|
||||
|
@ -508,7 +508,7 @@ describe('lib/image: image size', function () {
|
|||
imageSize.getImageSizeFromStoragePath(url)
|
||||
.catch(function (err) {
|
||||
should.exist(err);
|
||||
(err instanceof common.errors.NotFoundError).should.eql(true);
|
||||
(err instanceof errors.NotFoundError).should.eql(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const fs = require('fs-extra');
|
||||
const common = require('../../../../server/lib/common');
|
||||
const errors = require('@tryghost/errors');
|
||||
const manipulator = require('../../../../server/lib/image/manipulator');
|
||||
const testUtils = require('../../../utils');
|
||||
|
||||
|
@ -110,7 +110,7 @@ describe('lib/image: manipulator', function () {
|
|||
'1'.should.eql(1, 'Expected to fail');
|
||||
})
|
||||
.catch((err) => {
|
||||
(err instanceof common.errors.InternalServerError).should.be.true;
|
||||
(err instanceof errors.InternalServerError).should.be.true;
|
||||
err.code.should.eql('IMAGE_PROCESSING');
|
||||
});
|
||||
});
|
||||
|
@ -127,7 +127,7 @@ describe('lib/image: manipulator', function () {
|
|||
'1'.should.eql(1, 'Expected to fail');
|
||||
})
|
||||
.catch((err) => {
|
||||
(err instanceof common.errors.InternalServerError).should.be.true();
|
||||
(err instanceof errors.InternalServerError).should.be.true();
|
||||
err.code.should.eql('SHARP_INSTALLATION');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue