0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/server/errors.js
Hannah Wolfe 852155075f 🐛 Added 409 DisabledFeatureError for labs features (#8890)
fixes #8889

- This is a user error, not a system error
- Downgrading to a 4xx status code means it doesn't appear in logs where it shouldn't
- We didn't have a suitable error available so I added DisabledFeatureError with 409 status
- Ref: https://stackoverflow.com/questions/36874263/expected-http-status-code-for-an-action-on-a-disabled-resource
- Also tweaked the error message slightly as it didn't read clearly to me
2017-08-15 10:50:36 +02:00

81 lines
2.4 KiB
JavaScript

var _ = require('lodash'),
util = require('util'),
errors = require('ghost-ignition').errors;
function GhostError(options) {
options = options || {};
this.value = options.value;
errors.IgnitionError.call(this, options);
}
// jscs:disable
var ghostErrors = {
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));
},
DatabaseNotSeededError: function DatabaseNotSeededError(options) {
GhostError.call(this, _.merge({
statusCode: 500,
errorType: 'DatabaseNotSeededError'
}, options));
},
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));
},
DisabledFeatureError: function DisabledFeatureError(options) {
GhostError.call(this, _.merge({
statusCode: 409,
errorType: 'DisabledFeatureError',
}, options));
}
};
util.inherits(GhostError, errors.IgnitionError);
_.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) {
if (error.name === 'IgnitionError' || typeof error === 'object') {
return;
}
util.inherits(error, GhostError);
});
module.exports = _.merge(ghostErrors, errors);
module.exports.GhostError = GhostError;