Skip to content

Commit f6e927e

Browse files
Merge branch '4.4' into 5.4
* 4.4: MailerInterface: failed exception contract when enabling messenger add nonces to profiler
2 parents 9f2e421 + cb843f8 commit f6e927e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Mailer.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
use Symfony\Component\EventDispatcher\Event;
1616
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
1717
use Symfony\Component\Mailer\Event\MessageEvent;
18+
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
1819
use Symfony\Component\Mailer\Messenger\SendEmailMessage;
1920
use Symfony\Component\Mailer\Transport\TransportInterface;
21+
use Symfony\Component\Messenger\Exception\HandlerFailedException;
2022
use Symfony\Component\Messenger\MessageBusInterface;
2123
use Symfony\Component\Mime\RawMessage;
2224
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface;
@@ -52,6 +54,15 @@ public function send(RawMessage $message, Envelope $envelope = null): void
5254
$this->dispatcher->dispatch($event);
5355
}
5456

55-
$this->bus->dispatch(new SendEmailMessage($message, $envelope));
57+
try {
58+
$this->bus->dispatch(new SendEmailMessage($message, $envelope));
59+
} catch (HandlerFailedException $e) {
60+
foreach ($e->getNestedExceptions() as $nested) {
61+
if ($nested instanceof TransportExceptionInterface) {
62+
throw $nested;
63+
}
64+
}
65+
throw $e;
66+
}
5667
}
5768
}

0 commit comments

Comments
 (0)