mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Improved error messaging returned from JSON Schema validations
refs #10438
This commit is contained in:
parent
fa42a71181
commit
5f7c2b4d87
2 changed files with 12 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
const _ = require('lodash');
|
||||||
const Ajv = require('ajv');
|
const Ajv = require('ajv');
|
||||||
const stripKeyword = require('./strip-keyword');
|
const stripKeyword = require('./strip-keyword');
|
||||||
const common = require('../../../../../lib/common');
|
const common = require('../../../../../lib/common');
|
||||||
|
@ -14,8 +15,17 @@ const validate = (schema, definitions, data) => {
|
||||||
validation(data);
|
validation(data);
|
||||||
|
|
||||||
if (validation.errors) {
|
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({
|
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
|
errorDetails: validation.errors
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -648,6 +648,7 @@
|
||||||
"valueIsNotInteger": "Value in [{tableName}.{columnKey}] is not an integer.",
|
"valueIsNotInteger": "Value in [{tableName}.{columnKey}] is not an integer.",
|
||||||
"themeCannotBeActivated": "{themeName} cannot be activated because it is not currently installed.",
|
"themeCannotBeActivated": "{themeName} cannot be activated because it is not currently installed.",
|
||||||
"validationFailed": "Validation ({validationName}) failed for {key}",
|
"validationFailed": "Validation ({validationName}) failed for {key}",
|
||||||
|
"schemaValidationFailed": "Validation failed for '{key}'",
|
||||||
"validationFailedTypes": {
|
"validationFailedTypes": {
|
||||||
"isLength": "Value in [{tableName}.{key}] exceeds maximum length of {max} characters."
|
"isLength": "Value in [{tableName}.{key}] exceeds maximum length of {max} characters."
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue