ES6 migration: server/lib/common (#9779)

refs #9589
This commit is contained in:
Anonymous 2018-09-10 13:39:50 +01:00 committed by Hannah Wolfe
parent 27ae1b5163
commit e3ba60ca05

View File

@ -1,4 +1,5 @@
var _ = require('lodash'),
const merge = require('lodash/merge'),
each = require('lodash/each'),
util = require('util'),
errors = require('ghost-ignition').errors;
@ -9,59 +10,59 @@ function GhostError(options) {
errors.IgnitionError.call(this, options);
}
var ghostErrors = {
const ghostErrors = {
DataExportError: function DataExportError(options) {
GhostError.call(this, _.merge({
GhostError.call(this, merge({
statusCode: 500,
errorType: 'DataExportError'
}, options));
},
DataImportError: function DataImportError(options) {
GhostError.call(this, _.merge({
GhostError.call(this, merge({
statusCode: 500,
errorType: 'DataImportError'
}, options));
},
DatabaseVersionError: function DatabaseVersionError(options) {
GhostError.call(this, _.merge({
GhostError.call(this, merge({
hideStack: true,
statusCode: 500,
errorType: 'DatabaseVersionError'
}, options));
},
DatabaseNotPopulatedError: function DatabaseNotPopulatedError(options) {
GhostError.call(this, _.merge({
GhostError.call(this, merge({
statusCode: 500,
errorType: 'DatabaseNotPopulatedError'
}, options));
},
DatabaseNotSeededError: function DatabaseNotSeededError(options) {
GhostError.call(this, _.merge({
GhostError.call(this, merge({
statusCode: 500,
errorType: 'DatabaseNotSeededError'
}, options));
},
EmailError: function EmailError(options) {
GhostError.call(this, _.merge({
GhostError.call(this, merge({
statusCode: 500,
errorType: 'EmailError'
}, options));
},
ThemeValidationError: function ThemeValidationError(options) {
GhostError.call(this, _.merge({
GhostError.call(this, merge({
statusCode: 422,
errorType: 'ThemeValidationError',
errorDetails: {}
}, options));
},
DisabledFeatureError: function DisabledFeatureError(options) {
GhostError.call(this, _.merge({
GhostError.call(this, merge({
statusCode: 409,
errorType: 'DisabledFeatureError'
}, options));
},
UpdateCollisionError: function UpdateCollisionError(options) {
GhostError.call(this, _.merge({
GhostError.call(this, merge({
statusCode: 409,
errorType: 'UpdateCollisionError'
}, options));
@ -69,12 +70,12 @@ var ghostErrors = {
};
util.inherits(GhostError, errors.IgnitionError);
_.each(ghostErrors, function (error) {
each(ghostErrors, function (error) {
util.inherits(error, GhostError);
});
// we need to inherit all general errors from GhostError, otherwise we have to check instanceof IgnitionError
_.each(errors, function (error) {
each(errors, function (error) {
if (error.name === 'IgnitionError' || typeof error === 'object') {
return;
}
@ -82,5 +83,5 @@ _.each(errors, function (error) {
util.inherits(error, GhostError);
});
module.exports = _.merge(ghostErrors, errors);
module.exports = merge(ghostErrors, errors);
module.exports.GhostError = GhostError;