Search in sources :

Example 6 with ThrowableMessage

use of io.spine.base.ThrowableMessage in project core-java by SpineEventEngine.

the class CommandHandlerMethodShould method assertCauseAndId.

private static void assertCauseAndId(HandlerMethodFailedException e, Object handlerId) {
    final Throwable cause = getRootCause(e);
    assertTrue(cause instanceof ThrowableMessage);
    final ThrowableMessage thrown = (ThrowableMessage) cause;
    assertTrue(thrown.producerId().isPresent());
    assertEquals(handlerId, Identifier.unpack(thrown.producerId().get()));
}
Also used : ThrowableMessage(io.spine.base.ThrowableMessage)

Example 7 with ThrowableMessage

use of io.spine.base.ThrowableMessage in project core-java by SpineEventEngine.

the class CommandHandlerMethod method whyFailed.

/**
 * {@inheritDoc}
 *
 * <p>{@linkplain ThrowableMessage#initProducer(Any) Initializes} producer ID if the exception
 * was caused by a thrown rejection.
 */
@Override
protected HandlerMethodFailedException whyFailed(Object target, Message message, CommandContext context, Exception cause) {
    final HandlerMethodFailedException exception = super.whyFailed(target, message, context, cause);
    final Throwable rootCause = getRootCause(exception);
    if (rootCause instanceof ThrowableMessage) {
        final ThrowableMessage thrownMessage = (ThrowableMessage) rootCause;
        final Optional<Any> producerId = idOf(target);
        if (producerId.isPresent()) {
            thrownMessage.initProducer(producerId.get());
        }
    }
    return exception;
}
Also used : ThrowableMessage(io.spine.base.ThrowableMessage) HandlerMethodFailedException(io.spine.server.model.HandlerMethodFailedException) Any(com.google.protobuf.Any)

Aggregations

ThrowableMessage (io.spine.base.ThrowableMessage)7 Any (com.google.protobuf.Any)2 Message (com.google.protobuf.Message)2 Error (io.spine.base.Error)2 Internal (io.spine.annotation.Internal)1 Ack (io.spine.core.Ack)1 CommandClass (io.spine.core.CommandClass)1 CommandId (io.spine.core.CommandId)1 Rejection (io.spine.core.Rejection)1 Rejections.causedByRejection (io.spine.core.Rejections.causedByRejection)1 Rejections.toRejection (io.spine.core.Rejections.toRejection)1 CommandException (io.spine.server.commandbus.CommandException)1 HandlerMethodFailedException (io.spine.server.model.HandlerMethodFailedException)1 Exceptions.toError (io.spine.util.Exceptions.toError)1 Test (org.junit.Test)1