use of io.spine.base.FailureThrowable in project core-java by SpineEventEngine.
the class CommandStore method updateCommandStatus.
// OK for this consolidated error handling.
@SuppressWarnings("ChainOfInstanceofChecks")
public void updateCommandStatus(CommandEnvelope commandEnvelope, Throwable cause, Log log) {
final Message commandMessage = commandEnvelope.getMessage();
final CommandId commandId = commandEnvelope.getCommandId();
if (cause instanceof FailureThrowable) {
final FailureThrowable failure = (FailureThrowable) cause;
log.failureHandling(failure, commandMessage, commandId);
updateStatus(commandEnvelope, failure.toFailure(commandEnvelope.getCommand()));
} else if (cause instanceof Exception) {
final Exception exception = (Exception) cause;
log.errorHandling(exception, commandMessage, commandId);
updateStatus(commandEnvelope, exception);
} else {
log.errorHandlingUnknown(cause, commandMessage, commandId);
final Error error = Errors.fromThrowable(cause);
updateStatus(commandEnvelope, error);
}
}
use of io.spine.base.FailureThrowable in project core-java by SpineEventEngine.
the class CommandBus method emitFailure.
/**
* Emits the {@code Failure} and posts it to the {@code FailureBus},
* if the given {@code cause} is in fact a {@code FailureThrowable} instance.
*/
private void emitFailure(CommandEnvelope commandEnvelope, Throwable cause) {
if (cause instanceof FailureThrowable) {
final FailureThrowable failure = (FailureThrowable) cause;
failureBus.post(failure.toFailure(commandEnvelope.getCommand()), StreamObservers.<Response>noOpObserver());
}
}
Aggregations