Class ExceptionConverter

java.lang.Object
io.axoniq.framework.axonserver.connector.shared.ExceptionConverter

@Internal public final class ExceptionConverter extends Object
Utility class used to serialize Throwables into ErrorMessages, and to reconstruct AxonExceptions from error information received over the wire.

This class is used by the command and query connector implementations; it is not meant to be used directly by application code.

Since:
4.0.0
Author:
Marc Gathier
  • Method Details

    • convertToAxonException

      public static AxonException convertToAxonException(String errorCode, io.axoniq.axonserver.grpc.ErrorMessage errorMessage, io.axoniq.axonserver.grpc.SerializedObject payload, @Nullable Converter converter)
      Converts the given error information into an AxonException, attaching the given converter so that the resulting exception's details can be converted, on request, into whatever type the caller needs (see HandlerExecutionException#getDetails(Class)).

      The payload's raw bytes are not deserialized here. Deserialization is deferred until a caller asks for a specific details type, decoupling the thrower's details class (and version) from the receiver's.

      Parameters:
      errorCode - the error code identifying the type of exception to convert to
      errorMessage - the ErrorMessage containing details of the error
      payload - an optional SerializedObject representing additional error data, which may be used in the exception conversion
      converter - the Converter to attach to the resulting exception, so that details can be converted lazily, or null if no such conversion is available
      Returns:
      an instance of AxonException representing the given error information
    • convertToErrorMessage

      public static io.axoniq.axonserver.grpc.ErrorMessage convertToErrorMessage(@Nullable String clientLocation, @Nullable ErrorCode errorCode, Throwable t)
      Convert a given Throwable into an ErrorMessage.
      Parameters:
      clientLocation - the name of the client were the ErrorMessage originates from
      errorCode - the error code identifying the type of action that resulted in an error, if known
      t - the Throwable to base this ErrorMessage on
      Returns:
      the ErrorMessage originating from the given clientLocation and based on the Throwable
    • convertToDetails

      public static @Nullable io.axoniq.axonserver.grpc.SerializedObject convertToDetails(Throwable cause, @Nullable Converter converter)
      Converts the application-specific details carried by a HandlerExecutionException in the cause chain of the given cause, if any, into a SerializedObject suitable for putting on the wire.

      The type/revision on the resulting SerializedObject carry the runtime class name of the details object purely for wire-level observability/tracing. They are not used to reconstruct the details on the receiving side, since reconstruction is driven entirely by the type the receiver asks for.

      Parameters:
      cause - the exception to resolve application-specific details from
      converter - the Converter used to serialize the details into bytes, or null if none is available
      Returns:
      a SerializedObject carrying the serialized details, or null if there are no details, or the details could not be serialized