Class ExceptionUtils

java.lang.Object
net.solarnetwork.central.support.ExceptionUtils

public final class ExceptionUtils extends Object
Helpers for dealing with exceptions.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    generateErrorsMessage(org.springframework.validation.Errors e, Locale locale, org.springframework.context.MessageSource msgSrc)
    Generate an error message from an Errors instance.
    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 an Errors instance.
    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 an Errors instance.
    static org.springframework.validation.BindingResult
    toBindingResult(jakarta.validation.ConstraintViolationException e, jakarta.validation.Validator validator)
    Convert a constraint violation exception into a binding result.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • generateErrorsMessage

      public static String generateErrorsMessage(org.springframework.validation.Errors e, Locale locale, org.springframework.context.MessageSource msgSrc)
      Generate an error message from an Errors instance.
      Parameters:
      e - the errors
      locale - the locale
      msgSrc - 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 an Errors instance.

      The message will be generated via generateErrorsMessage(Errors, Locale, MessageSource).

      Type Parameters:
      V - the result type
      Parameters:
      e - the errors
      code - the optional error code
      locale - the locale
      msgSrc - 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 an Errors instance.

      Special handling of ConstraintViolation is performed to extract the error path, and rejected value.

      Type Parameters:
      V - the result type
      Parameters:
      e - the errors
      code - the optional error code
      message - the optional error message
      locale - the locale
      msgSrc - 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 exception
      validator - the validator
      object - the target object of the exception
      objectName - the target object name
      Returns:
      the result