Package net.solarnetwork.central.support
Class ExceptionUtils
java.lang.Object
net.solarnetwork.central.support.ExceptionUtils
Helpers for dealing with exceptions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgenerateErrorsMessage(org.springframework.validation.Errors e, Locale locale, org.springframework.context.MessageSource msgSrc) Generate an error message from anErrorsinstance.static <V> net.solarnetwork.domain.Result<V> generateErrorsResult(org.springframework.validation.Errors e, String code, String message, Locale locale, org.springframework.context.MessageSource msgSrc) Generate an error result from anErrorsinstance.static <V> net.solarnetwork.domain.Result<V> generateErrorsResult(org.springframework.validation.Errors e, String code, Locale locale, org.springframework.context.MessageSource msgSrc) Generate an error result from anErrorsinstance.static org.springframework.validation.BindingResulttoBindingResult(jakarta.validation.ConstraintViolationException e, jakarta.validation.Validator validator) Convert a constraint violation exception into a binding result.
-
Method Details
-
generateErrorsMessage
public static String generateErrorsMessage(org.springframework.validation.Errors e, Locale locale, org.springframework.context.MessageSource msgSrc) Generate an error message from anErrorsinstance.- Parameters:
e- the errorslocale- the localemsgSrc- the message source- Returns:
- the error message
-
generateErrorsResult
public static <V> net.solarnetwork.domain.Result<V> generateErrorsResult(org.springframework.validation.Errors e, String code, Locale locale, org.springframework.context.MessageSource msgSrc) Generate an error result from anErrorsinstance.The
messagewill be generated viagenerateErrorsMessage(Errors, Locale, MessageSource).- Type Parameters:
V- the result type- Parameters:
e- the errorscode- the optional error codelocale- the localemsgSrc- the message source- Returns:
- the result
-
generateErrorsResult
public static <V> net.solarnetwork.domain.Result<V> generateErrorsResult(org.springframework.validation.Errors e, String code, String message, Locale locale, org.springframework.context.MessageSource msgSrc) Generate an error result from anErrorsinstance.Special handling of
ConstraintViolationis performed to extract the error path, and rejected value.- Type Parameters:
V- the result type- Parameters:
e- the errorscode- the optional error codemessage- the optional error messagelocale- the localemsgSrc- the message source- Returns:
- the result
-
toBindingResult
public static org.springframework.validation.BindingResult toBindingResult(jakarta.validation.ConstraintViolationException e, jakarta.validation.Validator validator) Convert a constraint violation exception into a binding result.- Parameters:
e- the exceptionvalidator- the validatorobject- the target object of the exceptionobjectName- the target object name- Returns:
- the result
-