jsonpolice
Version:
JSON Schema parser and validator
40 lines • 1.02 kB
JavaScript
export class SchemaError extends Error {
scope;
info;
constructor(scope, type, info) {
super(type);
this.scope = scope;
this.info = info;
this.name = 'SchemaError';
}
}
export class ValidationError extends Error {
path;
scope;
errors;
constructor(path, scope, type, errors) {
super(type);
this.path = path;
this.scope = scope;
this.errors = errors;
this.name = 'ValidationError';
if (!this.path)
this.path = '/';
}
getInfo() {
return ValidationError.getInfo(this);
}
static getInfo(err) {
const out = { type: err.message };
if (err.name === 'ValidationError') {
const verr = err;
out.path = verr.path;
out.scope = verr.scope;
if (verr.errors) {
out.errors = verr.errors.map((e) => ValidationError.getInfo(e));
}
}
return out;
}
}
//# sourceMappingURL=errors.js.map