Prooph\ServiceBus\Exception\MessageDispatchException::failed PHP Method

failed() public static method

public static failed ( Prooph\Common\Event\ActionEvent $actionEvent, Exception $previousException = null ) : MessageDispatchException
$actionEvent Prooph\Common\Event\ActionEvent
$previousException Exception
return MessageDispatchException
    public static function failed(ActionEvent $actionEvent, \Exception $previousException = null)
    {
        $ex = new static(sprintf("Message dispatch failed during %s phase.%s", $actionEvent->getName(), null === $previousException ? '' : ' Error: ' . $previousException->getMessage()), 422, $previousException);
        $ex->setFailedDispatch($actionEvent);
        return $ex;
    }

Usage Example

 /**
  * @test
  */
 public function it_wraps_a_message_dispatch_exception_and_tracks_pending_commands()
 {
     $pendingCommands = ['dispatchMe', 'tellMe'];
     $actionEvent = new DefaultActionEvent(MessageBus::EVENT_INVOKE_HANDLER);
     $prevException = new \Exception('previous');
     $messageDispatchException = MessageDispatchException::failed($actionEvent, $prevException);
     $commandDispatchException = CommandDispatchException::wrap($messageDispatchException, $pendingCommands);
     $this->assertSame($actionEvent, $commandDispatchException->getFailedDispatchEvent());
     $this->assertSame($prevException, $commandDispatchException->getPrevious());
     $this->assertSame($pendingCommands, $commandDispatchException->getPendingCommands());
 }
All Usage Examples Of Prooph\ServiceBus\Exception\MessageDispatchException::failed