Inherits: 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 a validation exception and assigns its values.
public
ValidationException(string correlationId, string message, IList<ValidationResult> results)
- correlationId: string - (optional) unique transaction id used to trace execution through the call chain.
- message: string - (optional) human-readable description of the error.
- results: IList<ValidationResult> - (optional) list of validation results
Creates a new instance of a validation exception and assigns its values.
public
ValidationException(string correlationId, string message)
- correlationId: string - (optional) unique transaction id used to trace execution through the call chain.
- message: string - (optional) human-readable description of the error.
Static methods
ComposeMessage
Composes a human readable error message based on validation results.
public static
string ComposeMessage(IList<ValidationResult> results)
- results: IList<ValidationResult> - list of validation results.
- returns: string - composed error message.
FromResults
Creates a new ValidationException based on errors in validation results. If validation results have no errors, then null is returned.
public static
ValidationException FromResults(correlationId: string, List<ValidationResult> List<ValidationResult> results, bool strict)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- results: List<ValidationResult> - list of validation results that may contain errors.
- strict: bool - true to treat warnings as errors.
- returns: ValidationException - newly created ValidationException or null if no errors are found.
ThrowExceptionIfNeeded
Throws ValidationException based on errors in validation results. If validation results have no errors, then no exception is thrown.
public static
void ThrowExceptionIfNeeded(string correlationId, IList<ValidationResult> results, bool strict)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- results: IList<ValidationResult> - list of validation results that may contain errors
- strict: bool - true to treat warnings as errors.