From 96ffbbd27caa9127b53ca996dc96e5c44bfedd4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Sun, 18 Aug 2024 18:44:53 +0200 Subject: [PATCH] feat: explicit DSN error if invalid --- src/Controller/WatchListController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Controller/WatchListController.php b/src/Controller/WatchListController.php index a38c4f4..04a405c 100644 --- a/src/Controller/WatchListController.php +++ b/src/Controller/WatchListController.php @@ -35,7 +35,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -use Symfony\Component\Notifier\Exception\TransportExceptionInterface; +use Symfony\Component\Notifier\Exception\InvalidArgumentException; use Symfony\Component\Notifier\Transport\AbstractTransportFactory; use Symfony\Component\Notifier\Transport\Dsn; use Symfony\Component\Routing\Attribute\Route; @@ -51,14 +51,15 @@ class WatchListController extends AbstractController ) { } - /** - * @throws TransportExceptionInterface - */ private function verifyWebhookDSN(WatchList $watchList): void { if (null !== $watchList->getWebhookDsn()) { foreach ($watchList->getWebhookDsn() as $dsnString) { - $dsn = new Dsn($dsnString); + try { + $dsn = new Dsn($dsnString); + } catch (InvalidArgumentException $exception) { + throw new BadRequestHttpException($exception->getMessage()); + } $scheme = $dsn->getScheme(); $webhookScheme = WebhookScheme::tryFrom($scheme); @@ -66,6 +67,7 @@ class WatchListController extends AbstractController if (null === $webhookScheme) { throw new BadRequestHttpException("The DSN scheme ($scheme) is not supported"); } + $transportFactoryClass = $webhookScheme->getChatTransportFactory(); /** @var AbstractTransportFactory $transportFactory */ $transportFactory = new $transportFactoryClass();