Prooph\ServiceBus\Exception\CommandDispatchException::wrap PHP Method

wrap() public static method

public static wrap ( Exception $dispatchException, array $pendingCommands ) : CommandDispatchException
$dispatchException Exception
$pendingCommands array
return CommandDispatchException
    public static function wrap(\Exception $dispatchException, array $pendingCommands)
    {
        if ($dispatchException instanceof MessageDispatchException) {
            $ex = parent::failed($dispatchException->getFailedDispatchEvent(), $dispatchException->getPrevious());
            $ex->pendingCommands = $pendingCommands;
            return $ex;
        }
        $ex = new static("Command dispatch failed. See previous exception for details.", 422, $dispatchException);
        $ex->pendingCommands = $pendingCommands;
        return $ex;
    }

Usage Example

 /**
  * @test
  */
 public function it_can_also_wrap_a_normal_exception()
 {
     $pendingCommands = ['dispatchMe', 'tellMe'];
     $prevException = new \Exception('previous');
     $commandDispatchException = CommandDispatchException::wrap($prevException, $pendingCommands);
     $this->assertSame('Command dispatch failed. See previous exception for details.', $commandDispatchException->getMessage());
     $this->assertSame(422, $commandDispatchException->getCode());
     $this->assertSame($prevException, $commandDispatchException->getPrevious());
     $this->assertSame($pendingCommands, $commandDispatchException->getPendingCommands());
 }
All Usage Examples Of Prooph\ServiceBus\Exception\CommandDispatchException::wrap
CommandDispatchException