Create dedicated UnconfirmedOrderException
Create a dedicated UnconfirmedOrderException and use it from the OrderAggregate instead of the IllegalStateException BAEL-2435
This commit is contained in:
parent
65183f082d
commit
97ab713024
|
@ -13,6 +13,7 @@ import com.baeldung.axon.coreapi.commands.ShipOrderCommand;
|
|||
import com.baeldung.axon.coreapi.events.OrderConfirmedEvent;
|
||||
import com.baeldung.axon.coreapi.events.OrderPlacedEvent;
|
||||
import com.baeldung.axon.coreapi.events.OrderShippedEvent;
|
||||
import com.baeldung.axon.coreapi.exceptions.UnconfirmedOrderException;
|
||||
|
||||
@Aggregate
|
||||
public class OrderAggregate {
|
||||
|
@ -34,7 +35,7 @@ public class OrderAggregate {
|
|||
@CommandHandler
|
||||
public void handle(ShipOrderCommand command) {
|
||||
if (!orderConfirmed) {
|
||||
throw new IllegalStateException("Cannot ship an order which has not been confirmed yet.");
|
||||
throw new UnconfirmedOrderException();
|
||||
}
|
||||
|
||||
apply(new OrderShippedEvent(orderId));
|
||||
|
@ -43,12 +44,12 @@ public class OrderAggregate {
|
|||
@EventSourcingHandler
|
||||
public void on(OrderPlacedEvent event) {
|
||||
this.orderId = event.getOrderId();
|
||||
orderConfirmed = false;
|
||||
this.orderConfirmed = false;
|
||||
}
|
||||
|
||||
@EventSourcingHandler
|
||||
public void on(OrderConfirmedEvent event) {
|
||||
orderConfirmed = true;
|
||||
this.orderConfirmed = true;
|
||||
}
|
||||
|
||||
protected OrderAggregate() {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.axon.coreapi.exceptions;
|
||||
|
||||
public class UnconfirmedOrderException extends IllegalStateException {
|
||||
|
||||
public UnconfirmedOrderException() {
|
||||
super("Cannot ship an order which has not been confirmed yet.");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue