Class ThrowingErrorHandler

java.lang.Object
io.fluxzero.sdk.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.

Warning: this handler does not retry or automatically resume. It logs the error (if configured) and rethrows the original Throwable, which can stop the affected tracker until explicit restart, typically application restart or redeployment after repair. This includes FunctionalException: an ordinary business rejection can stop further processing by that tracker. Other trackers or application instances may continue.

Start with the default LoggingErrorHandler. Use this policy only for a deliberate operator-controlled stop, with alerts and a repair/restart procedure. When recoverable failures should be retried automatically and all repeated effects are safe, consider RetryingErrorHandler or ForeverRetryingErrorHandler instead. Stopping does not roll back effects already completed; recovery may deliver the failed work again.

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 = "operator-controlled-projection", errorHandler = ThrowingErrorHandler.class)
public class OperatorControlledProjection {
    @HandleEvent
    void on(ProjectionUpdated event) {
        // On failure: alert, repair, then explicitly restart tracking
    }
}
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