Skip to content

Commit c23211d

Browse files
committed
ImapConnectionException
1 parent 69378c5 commit c23211d

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Domain\Messaging\Exception;
6+
7+
use RuntimeException;
8+
use Throwable;
9+
10+
class ImapConnectionException extends RuntimeException
11+
{
12+
public function __construct(?Throwable $previous = null)
13+
{
14+
parent::__construct('Cannot connect to IMAP server', 0, $previous);
15+
16+
}
17+
}

src/Domain/Messaging/Service/WebklexBounceProcessingService.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use DateTimeImmutable;
88
use DateTimeInterface;
9+
use PhpList\Core\Domain\Messaging\Exception\ImapConnectionException;
910
use PhpList\Core\Domain\Messaging\Service\Manager\BounceManager;
1011
use PhpList\Core\Domain\Messaging\Service\Processor\BounceDataProcessor;
1112
use Psr\Log\LoggerInterface;
12-
use RuntimeException;
1313
use Throwable;
1414
use Webklex\PHPIMAP\Client;
1515
use Webklex\PHPIMAP\Folder;
@@ -50,7 +50,7 @@ public function __construct(
5050
*
5151
* $mailbox: IMAP host; if you pass "host#FOLDER", FOLDER will be used instead of INBOX.
5252
*
53-
* @throws RuntimeException If connection to the IMAP server cannot be established.
53+
* @throws ImapConnectionException If connection to the IMAP server cannot be established.
5454
*/
5555
public function processMailbox(
5656
string $mailbox,
@@ -61,9 +61,12 @@ public function processMailbox(
6161

6262
try {
6363
$client->connect();
64-
} catch (Throwable $e) {
65-
$this->logger->error('Cannot connect to mailbox: '.$e->getMessage());
66-
throw new RuntimeException('Cannot connect to IMAP server');
64+
} catch (Throwable $throwable) {
65+
$this->logger->error('Cannot connect to mailbox', [
66+
'mailbox' => $mailbox,
67+
'error' => $throwable->getMessage()
68+
]);
69+
throw new ImapConnectionException($throwable);
6770
}
6871

6972
try {

0 commit comments

Comments
 (0)