From 8ea86b41fa6f405de3d3e45c1ee17eba35d61863 Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Wed, 10 Jul 2024 19:26:18 +0200 Subject: [PATCH] Ignore exceptions when a resource can not be found We silently ignore exceptions when a resource can not be found. This may happen, when a language switcher is mounted on a 404 page but that one is not routable. We now return an empty URL in this case instead of bailing with an HTTP 500. --- src/Module/ModuleLanguageSwitcher.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Module/ModuleLanguageSwitcher.php b/src/Module/ModuleLanguageSwitcher.php index c164175..d3f4d08 100644 --- a/src/Module/ModuleLanguageSwitcher.php +++ b/src/Module/ModuleLanguageSwitcher.php @@ -16,6 +16,7 @@ use Hofff\Contao\LanguageRelations\LanguageRelations; use Hofff\Contao\LanguageRelations\Util\ContaoUtil; use Locale; +use Symfony\Component\Routing\Exception\ResourceNotFoundException; use function array_filter; use function array_flip; @@ -144,6 +145,8 @@ protected function compile(): void $url = $page->getFrontendUrl($params, $language); } catch (RouteParametersException $exception) { $url = ''; + } catch (ResourceNotFoundException $exception) { + $url = ''; } $item = [];