Class ThrowingErrorHandler
java.lang.Object
io.fluxzero.sdk.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 iflogTechnicalErrorsistrue. FunctionalExceptions are logged iflogFunctionalErrorsistrue.- In either case, the log level is
ERRORand 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 voidLogs the given error based on its type and logging configuration.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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:
handleErrorin interfaceErrorHandler- Parameters:
error- theThrowableencountered 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
-