mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Improved error messaging returned from JSON Schema validations
refs #10438
This commit is contained in:
parent
fa42a71181
commit
5f7c2b4d87
@ -1,3 +1,4 @@
|
||||
const _ = require('lodash');
|
||||
const Ajv = require('ajv');
|
||||
const stripKeyword = require('./strip-keyword');
|
||||
const common = require('../../../../../lib/common');
|
||||
@ -14,8 +15,17 @@ const validate = (schema, definitions, data) => {
|
||||
validation(data);
|
||||
|
||||
if (validation.errors) {
|
||||
let key;
|
||||
const dataPath = _.get(validation, 'errors[0].dataPath');
|
||||
|
||||
if (dataPath) {
|
||||
key = dataPath.split('.').pop();
|
||||
}
|
||||
|
||||
return Promise.reject(new common.errors.ValidationError({
|
||||
message: common.i18n.t('notices.data.validation.index.validationFailed'),
|
||||
message: common.i18n.t('notices.data.validation.index.schemaValidationFailed', {
|
||||
key: key
|
||||
}),
|
||||
errorDetails: validation.errors
|
||||
}));
|
||||
}
|
||||
|
@ -648,6 +648,7 @@
|
||||
"valueIsNotInteger": "Value in [{tableName}.{columnKey}] is not an integer.",
|
||||
"themeCannotBeActivated": "{themeName} cannot be activated because it is not currently installed.",
|
||||
"validationFailed": "Validation ({validationName}) failed for {key}",
|
||||
"schemaValidationFailed": "Validation failed for '{key}'",
|
||||
"validationFailedTypes": {
|
||||
"isLength": "Value in [{tableName}.{key}] exceeds maximum length of {max} characters."
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user