2021-06-17 12:17:55 +03:00
|
|
|
const merge = require('lodash/merge');
|
|
|
|
const each = require('lodash/each');
|
|
|
|
const util = require('util');
|
|
|
|
const errors = require('@tryghost/ignition-errors');
|
2017-12-11 22:27:09 +03:00
|
|
|
|
2021-06-17 12:17:55 +03:00
|
|
|
class GhostError extends errors.IgnitionError {
|
|
|
|
constructor(options) {
|
|
|
|
options = options || {};
|
|
|
|
super(options);
|
|
|
|
this.value = options.value;
|
|
|
|
}
|
2017-12-11 22:27:09 +03:00
|
|
|
}
|
|
|
|
|
2018-09-10 15:39:50 +03:00
|
|
|
const ghostErrors = {
|
2021-06-17 12:17:55 +03:00
|
|
|
DataExportError: class DataExportError extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DataExportError'
|
|
|
|
}, options));
|
|
|
|
}
|
2017-12-11 22:27:09 +03:00
|
|
|
},
|
2021-06-17 12:17:55 +03:00
|
|
|
DataImportError: class DataImportError extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DataImportError'
|
|
|
|
}, options));
|
|
|
|
}
|
2017-12-11 22:27:09 +03:00
|
|
|
},
|
2021-06-17 12:17:55 +03:00
|
|
|
DatabaseVersionError: class DatabaseVersionError extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
hideStack: true,
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'DatabaseVersionError'
|
|
|
|
}, options));
|
|
|
|
}
|
2017-12-11 22:27:09 +03:00
|
|
|
},
|
2021-06-17 12:17:55 +03:00
|
|
|
EmailError: class EmailError extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
statusCode: 500,
|
|
|
|
errorType: 'EmailError'
|
|
|
|
}, options));
|
|
|
|
}
|
2017-12-11 22:27:09 +03:00
|
|
|
},
|
2021-06-17 12:17:55 +03:00
|
|
|
ThemeValidationError: class ThemeValidationError extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
statusCode: 422,
|
|
|
|
errorType: 'ThemeValidationError',
|
|
|
|
errorDetails: {}
|
|
|
|
}, options));
|
|
|
|
}
|
2017-12-11 22:27:09 +03:00
|
|
|
},
|
2021-06-17 12:17:55 +03:00
|
|
|
DisabledFeatureError: class DisabledFeatureError extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
statusCode: 409,
|
|
|
|
errorType: 'DisabledFeatureError'
|
|
|
|
}, options));
|
|
|
|
}
|
2017-12-11 22:27:09 +03:00
|
|
|
},
|
2021-06-17 12:17:55 +03:00
|
|
|
UpdateCollisionError: class UpdateCollisionError extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
statusCode: 409,
|
|
|
|
errorType: 'UpdateCollisionError'
|
|
|
|
}, options));
|
|
|
|
}
|
2019-06-07 16:54:55 +03:00
|
|
|
},
|
2021-06-17 12:17:55 +03:00
|
|
|
HostLimitError: class HostLimitError extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
errorType: 'HostLimitError',
|
|
|
|
hideStack: true,
|
|
|
|
statusCode: 403
|
|
|
|
}, options));
|
|
|
|
}
|
2019-12-17 16:54:27 +03:00
|
|
|
},
|
2021-06-17 12:17:55 +03:00
|
|
|
HelperWarning: class HelperWarning extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
errorType: 'HelperWarning',
|
|
|
|
hideStack: true
|
|
|
|
}, options));
|
|
|
|
}
|
2020-05-26 19:09:44 +03:00
|
|
|
},
|
2021-06-17 12:17:55 +03:00
|
|
|
PasswordResetRequiredError: class PasswordResetRequiredError extends GhostError {
|
|
|
|
constructor(options) {
|
|
|
|
super(merge({
|
|
|
|
errorType: 'PasswordResetRequiredError',
|
|
|
|
statusCode: 401,
|
|
|
|
message: 'For security, you need to create a new password. An email has been sent to you with instructions!'
|
|
|
|
}, options));
|
|
|
|
}
|
2017-12-11 22:27:09 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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;
|