2018-09-10 15:39:50 +03:00
|
|
|
const merge = require('lodash/merge'),
|
|
|
|
each = require('lodash/each'),
|
2017-12-11 22:27:09 +03:00
|
|
|
util = require('util'),
|
|
|
|
errors = require('ghost-ignition').errors;
|
|
|
|
|
|
|
|
function GhostError(options) {
|
|
|
|
options = options || {};
|
|
|
|
this.value = options.value;
|
|
|
|
|
|
|
|
errors.IgnitionError.call(this, options);
|
|
|
|
}
|
|
|
|
|
2018-09-10 15:39:50 +03:00
|
|
|
const ghostErrors = {
|
2017-12-11 22:27:09 +03:00
|
|
|
DataExportError: function DataExportError(options) {
|
2018-09-10 15:39:50 +03:00
|
|
|
GhostError.call(this, merge({
|
2017-12-11 22:27:09 +03:00
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DataExportError'
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
DataImportError: function DataImportError(options) {
|
2018-09-10 15:39:50 +03:00
|
|
|
GhostError.call(this, merge({
|
2017-12-11 22:27:09 +03:00
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DataImportError'
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
DatabaseVersionError: function DatabaseVersionError(options) {
|
2018-09-10 15:39:50 +03:00
|
|
|
GhostError.call(this, merge({
|
2017-12-11 22:27:09 +03:00
|
|
|
hideStack: true,
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DatabaseVersionError'
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
EmailError: function EmailError(options) {
|
2018-09-10 15:39:50 +03:00
|
|
|
GhostError.call(this, merge({
|
2017-12-11 22:27:09 +03:00
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'EmailError'
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
ThemeValidationError: function ThemeValidationError(options) {
|
2018-09-10 15:39:50 +03:00
|
|
|
GhostError.call(this, merge({
|
2017-12-11 22:27:09 +03:00
|
|
|
statusCode: 422,
|
|
|
|
errorType: 'ThemeValidationError',
|
|
|
|
errorDetails: {}
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
DisabledFeatureError: function DisabledFeatureError(options) {
|
2018-09-10 15:39:50 +03:00
|
|
|
GhostError.call(this, merge({
|
2017-12-11 22:27:09 +03:00
|
|
|
statusCode: 409,
|
|
|
|
errorType: 'DisabledFeatureError'
|
|
|
|
}, options));
|
|
|
|
},
|
|
|
|
UpdateCollisionError: function UpdateCollisionError(options) {
|
2018-09-10 15:39:50 +03:00
|
|
|
GhostError.call(this, merge({
|
2017-12-11 22:27:09 +03:00
|
|
|
statusCode: 409,
|
|
|
|
errorType: 'UpdateCollisionError'
|
|
|
|
}, options));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
util.inherits(GhostError, errors.IgnitionError);
|
2018-09-10 15:39:50 +03:00
|
|
|
each(ghostErrors, function (error) {
|
2017-12-11 22:27:09 +03:00
|
|
|
util.inherits(error, GhostError);
|
|
|
|
});
|
|
|
|
|
|
|
|
// we need to inherit all general errors from GhostError, otherwise we have to check instanceof IgnitionError
|
2018-09-10 15:39:50 +03:00
|
|
|
each(errors, function (error) {
|
2017-12-11 22:27:09 +03:00
|
|
|
if (error.name === 'IgnitionError' || typeof error === 'object') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(error, GhostError);
|
|
|
|
});
|
|
|
|
|
2018-09-10 15:39:50 +03:00
|
|
|
module.exports = merge(ghostErrors, errors);
|
2017-12-11 22:27:09 +03:00
|
|
|
module.exports.GhostError = GhostError;
|