Skip to content

Commit

Permalink
Close #44: Set correct failed phase for dispatch exception
Browse files Browse the repository at this point in the history
- Allow listeners to unset exception
  • Loading branch information
codeliner committed Jan 12, 2015
1 parent a62989d commit a97c4ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/Prooph/ServiceBus/CommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion src/Prooph/ServiceBus/EventBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a97c4ab

Please sign in to comment.