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()));
}
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;
}
Aggregations