0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Merge pull request #6228 from ErisDS/filter-error-handling

Ensure filter parse errors generate 422 not 500
This commit is contained in:
Sebastian Gierlinger 2015-12-15 16:48:17 +01:00
commit 5184d6b74c

View file

@ -1,5 +1,6 @@
var _ = require('lodash'),
gql = require('ghost-gql'),
var _ = require('lodash'),
errors = require('../../errors'),
gql = require('ghost-gql'),
filter,
filterUtils;
@ -16,11 +17,19 @@ filterUtils = {
custom = Array.prototype.slice.call(arguments, 2);
// Ensure everything has been run through the gql parser
enforced = enforced ? (_.isString(enforced) ? gql.parse(enforced) : enforced) : null;
defaults = defaults ? (_.isString(defaults) ? gql.parse(defaults) : defaults) : null;
custom = _.map(custom, function (arg) {
return _.isString(arg) ? gql.parse(arg) : arg;
});
try {
enforced = enforced ? (_.isString(enforced) ? gql.parse(enforced) : enforced) : null;
defaults = defaults ? (_.isString(defaults) ? gql.parse(defaults) : defaults) : null;
custom = _.map(custom, function (arg) {
return _.isString(arg) ? gql.parse(arg) : arg;
});
} catch (error) {
errors.logAndThrowError(
new errors.ValidationError(error.message, 'filter'),
'Error parsing filter',
'For more information on how to use filter, see http://api.ghost.org/docs/filter'
);
}
// Merge custom filter options into a single set of statements
custom = gql.json.mergeStatements.apply(this, custom);