Skip to content

Commit

Permalink
Ignore exceptions when a resource can not be found
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
discordier authored Jul 10, 2024
1 parent a11f52a commit 8ea86b4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Module/ModuleLanguageSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,6 +145,8 @@ protected function compile(): void
$url = $page->getFrontendUrl($params, $language);
} catch (RouteParametersException $exception) {
$url = '';
} catch (ResourceNotFoundException $exception) {
$url = '';
}

$item = [];
Expand Down

0 comments on commit 8ea86b4

Please sign in to comment.