diff --git a/src/Prooph/ServiceBus/CommandBus.php b/src/Prooph/ServiceBus/CommandBus.php index 74e66a2..d6af654 100644 --- a/src/Prooph/ServiceBus/CommandBus.php +++ b/src/Prooph/ServiceBus/CommandBus.php @@ -150,10 +150,19 @@ public function dispatch($command) $this->trigger($commandDispatch); } catch (\Exception $ex) { + $failedPhase = $commandDispatch->getName(); + $commandDispatch->setException($ex); $this->triggerError($commandDispatch); $this->triggerFinalize($commandDispatch); - throw CommandDispatchException::failed($commandDispatch, $ex); + + //Check if a listener has removed the exception to indicate that it was able to handle it + if ($ex = $commandDispatch->getException()) { + $commandDispatch->setName($failedPhase); + throw CommandDispatchException::failed($commandDispatch, $ex); + } + + return; } $this->triggerFinalize($commandDispatch); diff --git a/src/Prooph/ServiceBus/EventBus.php b/src/Prooph/ServiceBus/EventBus.php index 0facb8e..1922430 100644 --- a/src/Prooph/ServiceBus/EventBus.php +++ b/src/Prooph/ServiceBus/EventBus.php @@ -139,10 +139,20 @@ public function dispatch($event) } } catch (\Exception $ex) { + $failedPhase = $eventDispatch->getName(); $eventDispatch->setException($ex); + $this->triggerError($eventDispatch); $this->triggerFinalize($eventDispatch); - throw EventDispatchException::failed($eventDispatch, $ex); + + //Check if a listener has removed the exception to indicate that it was able to handle it + if ($ex = $eventDispatch->getException()) { + $eventDispatch->setName($failedPhase); + throw EventDispatchException::failed($eventDispatch, $ex); + } + + return; + } $this->triggerFinalize($eventDispatch);