error_classes.ts 787 B

123456789101112131415161718192021222324252627282930
  1. import type {ErrorObject} from "../types"
  2. import {resolveUrl, normalizeId, getFullPath} from "./resolve"
  3. export class ValidationError extends Error {
  4. readonly errors: Partial<ErrorObject>[]
  5. readonly ajv: true
  6. readonly validation: true
  7. constructor(errors: Partial<ErrorObject>[]) {
  8. super("validation failed")
  9. this.errors = errors
  10. this.ajv = this.validation = true
  11. }
  12. }
  13. export class MissingRefError extends Error {
  14. readonly missingRef: string
  15. readonly missingSchema: string
  16. constructor(baseId: string, ref: string) {
  17. super(`can't resolve reference ${ref} from id ${baseId}`)
  18. this.missingRef = resolveUrl(baseId, ref)
  19. this.missingSchema = normalizeId(getFullPath(this.missingRef))
  20. }
  21. }
  22. module.exports = {
  23. ValidationError,
  24. MissingRefError,
  25. }