Class ThrowingErrorHandler
java.lang.Object
io.fluxcapacitor.javaclient.tracking.ThrowingErrorHandler
- All Implemented Interfaces:
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 iflogTechnicalErrors
istrue
. FunctionalException
s are logged iflogFunctionalErrors
istrue
.- 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 Summary
ConstructorsConstructorDescriptionConstructs a default ThrowingErrorHandler that logs both functional and technical errors. -
Method Summary
Modifier and TypeMethodDescriptionhandleError
(Throwable error, String errorMessage, Callable<?> retryFunction) Handles the given error by optionally logging it and then throwing it to halt message tracking.protected void
Logs the given error based on its type and logging configuration.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.ErrorHandler
handleError
-
Constructor Details
-
ThrowingErrorHandler
public ThrowingErrorHandler()Constructs a default ThrowingErrorHandler that logs both functional and technical errors.
-
-
Method Details
-
handleError
Handles the given error by optionally logging it and then throwing it to halt message tracking.- Specified by:
handleError
in interfaceErrorHandler
- Parameters:
error
- theThrowable
encountered during message processingerrorMessage
- context about the failureretryFunction
- the operation that was attempted (ignored in this implementation)- Returns:
- never returns normally – always throws the original error
-
logError
Logs the given error based on its type and logging configuration.- Parameters:
error
- the error to logerrorMessage
- message to accompany the log entry
-