You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
828 B

4 years ago
  1. 'use strict';
  2. var resolve = require('./resolve');
  3. module.exports = {
  4. Validation: errorSubclass(ValidationError),
  5. MissingRef: errorSubclass(MissingRefError)
  6. };
  7. function ValidationError(errors) {
  8. this.message = 'validation failed';
  9. this.errors = errors;
  10. this.ajv = this.validation = true;
  11. }
  12. MissingRefError.message = function (baseId, ref) {
  13. return 'can\'t resolve reference ' + ref + ' from id ' + baseId;
  14. };
  15. function MissingRefError(baseId, ref, message) {
  16. this.message = message || MissingRefError.message(baseId, ref);
  17. this.missingRef = resolve.url(baseId, ref);
  18. this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef));
  19. }
  20. function errorSubclass(Subclass) {
  21. Subclass.prototype = Object.create(Error.prototype);
  22. Subclass.prototype.constructor = Subclass;
  23. return Subclass;
  24. }