Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Commit 3a3e0d3

Browse files
committed
Add connection exception.
1 parent 3b2865a commit 3a3e0d3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/CeleryAbstract.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Celery;
44

5+
use PhpAmqpLib\Exception\AMQPProtocolConnectionException;
6+
57
/**
68
* Client for a Celery server - abstract base class implementing actual logic
79
* @package celery-php
@@ -57,10 +59,21 @@ public function BuildConnection($connection_details, $is_backend = false)
5759
}
5860
}
5961

62+
/**
63+
* @throws CeleryConnectionException on connection failure.
64+
*/
6065
public static function InitializeAMQPConnection($details)
6166
{
6267
$amqp = AbstractAMQPConnector::GetConcrete($details['connector']);
63-
return $amqp->GetConnectionObject($details);
68+
try {
69+
return $amqp->GetConnectionObject($details);
70+
}
71+
catch (AMQPProtocolConnectionException $e) {
72+
throw new CeleryConnectionException("Failed to establish a AMQP connection. Check credentials.");
73+
}
74+
catch (Exception $e) {
75+
throw new CeleryConnectionException("Failed to establish a AMQP connection. Unspecified failure.");
76+
}
6477
}
6578

6679
/**

src/CeleryConnectionException.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Celery;
4+
5+
/**
6+
* Emited by CeleryAbstract::PostTask() connection failures etc
7+
* @package celery-php
8+
*/
9+
class CeleryConnectionException extends CeleryException
10+
{
11+
}

0 commit comments

Comments
 (0)