Class ThrowingErrorHandler

java.lang.Object
io.fluxcapacitor.javaclient.tracking.ThrowingErrorHandler
All Implemented Interfaces:
ErrorHandler

public class ThrowingErrorHandler extends Object implements ErrorHandler
An ErrorHandler implementation that forcefully halts message tracking by throwing any encountered errors.

This handler is designed for critical scenarios where continuation after an error is not acceptable, such as:

  • Data integrity violations
  • Irrecoverable technical failures
  • Strict consistency or audit requirements

Upon encountering an error, this handler logs the issue (if configured to do so) and rethrows the original Throwable. This causes message tracking to stop until it is explicitly restarted—typically after resolving the failure or redeploying the application.

Logging Behavior:

  • Technical exceptions (i.e., not FunctionalException) are logged if logTechnicalErrors is true.
  • FunctionalExceptions are logged if logFunctionalErrors is true.
  • In either case, the log level is ERROR and includes the full stack trace.

Usage: Can be registered via Consumer.errorHandler() or programmatically via ConsumerConfiguration.


 @Consumer(name = "criticalConsumer", errorHandler = ThrowingErrorHandler.class)
 public class CriticalHandler {
     @HandleCommand
     void handle(UpdateBankBalance command) {
         // Fails fast on any error
     }
 }
 
See Also:
  • Constructor Details

    • ThrowingErrorHandler

      public ThrowingErrorHandler()
      Constructs a default ThrowingErrorHandler that logs both functional and technical errors.
  • Method Details

    • handleError

      public Object handleError(Throwable error, String errorMessage, Callable<?> retryFunction)
      Handles the given error by optionally logging it and then throwing it to halt message tracking.
      Specified by:
      handleError in interface ErrorHandler
      Parameters:
      error - the Throwable encountered during message processing
      errorMessage - context about the failure
      retryFunction - the operation that was attempted (ignored in this implementation)
      Returns:
      never returns normally – always throws the original error
    • logError

      protected void logError(Throwable error, String errorMessage)
      Logs the given error based on its type and logging configuration.
      Parameters:
      error - the error to log
      errorMessage - message to accompany the log entry