Class ValidationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
org.pipservices3.commons.errors.ApplicationException
org.pipservices3.commons.errors.BadRequestException
org.pipservices3.commons.validate.ValidationException
- All Implemented Interfaces:
Serializable
Errors in schema validation.
Validation errors are usually generated based in ValidationResult
.
If using strict mode, warnings will also raise validation exceptions.
-
Constructor Summary
ConstructorsConstructorDescriptionValidationException
(String correlationId, String message) Creates a new instance of validation exception and assigns its values.ValidationException
(String correlationId, List<ValidationResult> results) Creates a new instance of validation exception and assigns its values. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
composeMessage
(List<ValidationResult> results) Composes human readable error message based on validation results.static ValidationException
fromResults
(String correlationId, List<ValidationResult> results, boolean strict) Creates a new ValidationException based on errors in validation results.static void
throwExceptionIfNeeded
(String correlationId, List<ValidationResult> results, boolean strict) Throws ValidationException based on errors in validation results.Methods inherited from class org.pipservices3.commons.errors.ApplicationException
getCategory, getCauseString, getCode, getCorrelationId, getDetails, getMessage, getStackTraceString, getStatus, setCategory, setCauseString, setCode, setCorrelationId, setDetails, setMessage, setStackTraceString, setStatus, withCause, withCode, withCorrelationId, withDetails, withStackTrace, withStatus, wrap, wrapException
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
ValidationException
Creates a new instance of validation exception and assigns its values.- Parameters:
correlationId
- (optional) a unique transaction id to trace execution through call chain.results
- (optional) a list of validation results- See Also:
-
ValidationException
Creates a new instance of validation exception and assigns its values.- Parameters:
correlationId
- (optional) a unique transaction id to trace execution through call chain.message
- (optional) a human-readable description of the error.- See Also:
-
-
Method Details
-
composeMessage
Composes human readable error message based on validation results.- Parameters:
results
- a list of validation results.- Returns:
- a composed error message.
- See Also:
-
fromResults
public static ValidationException fromResults(String correlationId, List<ValidationResult> results, boolean strict) throws ValidationException Creates a new ValidationException based on errors in validation results. If validation results have no errors, than null is returned.- Parameters:
correlationId
- (optional) transaction id to trace execution through call chain.results
- list of validation results that may contain errorsstrict
- true to treat warnings as errors.- Returns:
- a newly created ValidationException or null if no errors in found.
- Throws:
ValidationException
- when errors occured in validation.- See Also:
-
throwExceptionIfNeeded
public static void throwExceptionIfNeeded(String correlationId, List<ValidationResult> results, boolean strict) throws ValidationException Throws ValidationException based on errors in validation results. If validation results have no errors, than no exception is thrown.- Parameters:
correlationId
- (optional) transaction id to trace execution through call chain.results
- list of validation results that may contain errorsstrict
- true to treat warnings as errors.- Throws:
ValidationException
- when errors occured in validation.- See Also:
-