@gabliam/validate-joi
Version:
Gabliam plugin for add validation with joi on web
34 lines (33 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createValidationException = void 0;
const tslib_1 = require("tslib");
const web_core_1 = require("@gabliam/web-core");
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
const getKeys = (error, options) => {
const keys = [];
if (error.details) {
for (let i = 0; i < error.details.length; i += 1) {
/* istanbul ignore next */
const path = Array.isArray(error.details[i].path)
? error.details[i].path.join('.')
: error.details[i].path;
let k;
if (options.escapeHtml) {
k = (0, escape_html_1.default)(path);
}
else {
k = path;
}
keys.push(k);
}
}
return keys;
};
const createValidationException = (error, source, options) => new web_core_1.BadRequestException(error.message, undefined, {
validation: {
source,
keys: getKeys(error, options),
},
});
exports.createValidationException = createValidationException;