2016-10-06 15:27:35 +03:00
|
|
|
var _ = require('lodash'),
|
2017-01-23 14:04:01 +03:00
|
|
|
util = require('util'),
|
|
|
|
errors = require('ghost-ignition').errors;
|
2016-10-06 15:27:35 +03:00
|
|
|
|
|
|
|
function GhostError(options) {
|
|
|
|
options = options || {};
|
|
|
|
this.value = options.value;
|
|
|
|
|
2017-01-23 14:04:01 +03:00
|
|
|
errors.IgnitionError.call(this, options);
|
2016-10-06 15:27:35 +03:00
|
|
|
}
|
|
|
|
|
2017-01-23 14:04:01 +03:00
|
|
|
var ghostErrors = {
|
2016-10-06 15:27:35 +03:00
|
|
|
DataExportError: function DataExportError(options) {
|
|
|
|
GhostError.call(this, _.merge({
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DataExportError'
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
DataImportError: function DataImportError(options) {
|
|
|
|
GhostError.call(this, _.merge({
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DataImportError'
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
DatabaseVersionError: function DatabaseVersionError(options) {
|
|
|
|
GhostError.call(this, _.merge({
|
|
|
|
hideStack: true,
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DatabaseVersionError'
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
DatabaseNotPopulatedError: function DatabaseNotPopulatedError(options) {
|
|
|
|
GhostError.call(this, _.merge({
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DatabaseNotPopulatedError'
|
|
|
|
}, options));
|
|
|
|
},
|
2016-10-06 16:50:55 +03:00
|
|
|
DatabaseNotSeededError: function DatabaseNotSeededError(options) {
|
|
|
|
GhostError.call(this, _.merge({
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DatabaseNotSeededError'
|
|
|
|
}, options));
|
|
|
|
},
|
2016-10-06 15:27:35 +03:00
|
|
|
EmailError: function EmailError(options) {
|
|
|
|
GhostError.call(this, _.merge({
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'EmailError'
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
ThemeValidationError: function ThemeValidationError(options) {
|
|
|
|
GhostError.call(this, _.merge({
|
|
|
|
statusCode: 422,
|
|
|
|
errorType: 'ThemeValidationError',
|
|
|
|
errorDetails: {}
|
|
|
|
}, options));
|
2017-08-15 11:50:36 +03:00
|
|
|
},
|
|
|
|
DisabledFeatureError: function DisabledFeatureError(options) {
|
|
|
|
GhostError.call(this, _.merge({
|
|
|
|
statusCode: 409,
|
2017-11-01 16:44:54 +03:00
|
|
|
errorType: 'DisabledFeatureError'
|
2017-08-15 11:50:36 +03:00
|
|
|
}, options));
|
2017-08-15 13:06:40 +03:00
|
|
|
},
|
|
|
|
UpdateCollisionError: function UpdateCollisionError(options) {
|
|
|
|
GhostError.call(this, _.merge({
|
|
|
|
statusCode: 409,
|
2017-11-01 16:44:54 +03:00
|
|
|
errorType: 'UpdateCollisionError'
|
2017-08-15 13:06:40 +03:00
|
|
|
}, options));
|
2016-10-06 15:27:35 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-23 14:04:01 +03:00
|
|
|
util.inherits(GhostError, errors.IgnitionError);
|
|
|
|
_.each(ghostErrors, function (error) {
|
2016-10-06 15:27:35 +03:00
|
|
|
util.inherits(error, GhostError);
|
|
|
|
});
|
|
|
|
|
2017-01-23 14:04:01 +03:00
|
|
|
// we need to inherit all general errors from GhostError, otherwise we have to check instanceof IgnitionError
|
|
|
|
_.each(errors, function (error) {
|
|
|
|
if (error.name === 'IgnitionError' || typeof error === 'object') {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-06 15:27:35 +03:00
|
|
|
|
2017-01-23 14:04:01 +03:00
|
|
|
util.inherits(error, GhostError);
|
|
|
|
});
|
2016-10-06 15:27:35 +03:00
|
|
|
|
2017-01-23 14:04:01 +03:00
|
|
|
module.exports = _.merge(ghostErrors, errors);
|
|
|
|
module.exports.GhostError = GhostError;
|