ValidationException

Errors in schema validation.

Extends: BadRequestException

Description

The ValidationException is used to define errors in schema validation.

Important points

  • Validation errors are usually generated based in ValidationResult.
  • If using strict mode, warnings will also raise validation exceptions.

Constructors

Creates a new instance of validation exception and assigns its values.

public constructor(correlationId: string, message?: string, results?: ValidationResult[])

  • correlationId: string - (optional) a unique transaction id to trace execution through call chain.
  • message: string - (optional) a human-readable description of the error.
  • results: ValidationResult[] - (optional) a list of validation results

Static methods

composeMessage

Composes human readable error message based on validation results.

public static composeMessage(results: ValidationResult[]): string

  • results: ValidationResult[] - a list of validation results.
  • returns: string - a composed error message.

fromResults

Creates a new ValidationException based on errors in validation results. If validation results have no errors, than null is returned.

public static fromResults(correlationId: string, results: ValidationResult[], strict: boolean): ValidationException

  • correlationId: string - (optional) transaction id to trace execution through call chain.
  • results: ValidationResult[] - list of validation results that may contain errors
  • strict: boolean - true to treat warnings as errors.
  • returns: ValidationException - a newly created ValidationException or null if no errors in found.

throwExceptionIfNeeded

Throws ValidationException based on errors in validation results. If validation results have no errors, than no exception is thrown.

public static throwExceptionIfNeeded(correlationId: string, results: ValidationResult[], strict: boolean): void

  • correlationId: string - (optional) transaction id to trace execution through call chain.
  • results: ValidationResult[] - list of validation results that may contain errors
  • strict: boolean - true to treat warnings as errors.

See also