[Messenger] Display a nice error when connection fail

This commit is contained in:
Grégoire Pineau 2019-03-16 02:50:06 +01:00
parent 0762d2d9ac
commit eac014febd

View File

@ -199,10 +199,14 @@ class Connection
$connection = $this->amqpFactory->createConnection($this->connectionCredentials);
$connectMethod = 'true' === ($this->connectionCredentials['persistent'] ?? 'false') ? 'pconnect' : 'connect';
if (false === $connection->{$connectMethod}()) {
throw new \AMQPException('Could not connect to the AMQP server. Please verify the provided DSN.');
}
try {
$connection->{$connectMethod}();
} catch (\AMQPConnectionException $e) {
$credentials = $this->connectionCredentials;
$credentials['password'] = '********';
throw new \AMQPException(sprintf('Could not connect to the AMQP server. Please verify the provided DSN. (%s)', json_encode($credentials)), 0, $e);
}
$this->amqpChannel = $this->amqpFactory->createChannel($connection);
}