jet-schema
Version:
Simple, typescript-first schema validation tool
57 lines • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Errors = void 0;
exports.defaultOnError = defaultOnError;
exports.getErrObj = getErrObj;
const util_1 = require("./util");
exports.Errors = {
Init: '"init:" option must be "true" if schema is not optional.',
DefaultVal: 'Default value did not pass validation.',
Validator: 'Validator must be a function, enum, nested-schema, or ' +
'Date() constructor.',
PropValidation: 'Validator function failed.',
UndefButNotOpt: 'Argument was undefined but not optional.',
NullButNotNullable: 'Argument was null but not nullable',
NotAnObj: 'Argument must be an object.',
StrictMode: 'Extra properties not allowed in strict mode.',
};
function defaultOnError(errors) {
if (!!errors) {
if (Array.isArray(errors) && !(errors.length > 0)) {
return;
}
let errorsF;
if (!(0, util_1.isStr)(errors)) {
if (Array.isArray(errors) && (errors.length === 1)) {
errorsF = JSON.stringify(errors[0]);
}
else {
errorsF = JSON.stringify(errors);
}
}
else {
errorsF = errors;
}
throw new Error(errorsF);
}
}
function getErrObj(message, location, schemaId, property, value) {
const error = {};
if (!!property) {
error.property = property;
}
if (arguments.length === 5) {
error.value = value;
}
if (!!message) {
error.message = message;
}
if (!!location) {
error.location = location;
}
if (!!schemaId) {
error.schemaId = schemaId;
}
return error;
}
//# sourceMappingURL=error-stuff.js.map