2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Improved error messaging returned from JSON Schema validations

refs #10438
This commit is contained in:
Nazar Gargol 2019-02-14 10:52:42 +00:00
parent fa42a71181
commit 5f7c2b4d87
2 changed files with 12 additions and 1 deletions

View file

@ -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
}));
}

View file

@ -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."
}