Search in sources :

Example 1 with FailureThrowable

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);
    }
}
Also used : Message(com.google.protobuf.Message) FailureThrowable(io.spine.base.FailureThrowable) Error(io.spine.base.Error) CommandId(io.spine.base.CommandId) CommandException(io.spine.server.commandbus.CommandException)

Example 2 with FailureThrowable

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());
    }
}
Also used : FailureThrowable(io.spine.base.FailureThrowable)

Aggregations

FailureThrowable (io.spine.base.FailureThrowable)2 Message (com.google.protobuf.Message)1 CommandId (io.spine.base.CommandId)1 Error (io.spine.base.Error)1 CommandException (io.spine.server.commandbus.CommandException)1