Skip to content

Commit

Permalink
UHF-8837: handle environment_resolver exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Sep 4, 2023
1 parent cd70092 commit 9ba6229
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions helfi_proxy.module
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,26 @@ function helfi_proxy_simple_sitemap_links_alter(array &$links, $sitemap_variant)
return;
}

/** @var \Drupal\helfi_api_base\Environment\Environment $environment */
$environment = \Drupal::service('helfi_api_base.environment_resolver')->getActiveEnvironment();
try {
/** @var \Drupal\helfi_api_base\Environment\Environment $environment */
$environment = \Drupal::service('helfi_api_base.environment_resolver')->getActiveEnvironment();
} catch (\InvalidArgumentException) {
return;
}

/** @var \Drupal\Core\Path\PathMatcherInterface $pathMatcher */
$pathMatcher = \Drupal::service('path.matcher');

// helfi_proxy module sets "X-Robots-Tag: noindex" header for configured
// paths. These url should not be included in the sitemap.xml file.
foreach ($links as $key => $link) {
$baseUrl = $environment->getUrl($link['langcode']);
try {
$baseUrl = $environment->getUrl($link['langcode']);
} catch (\InvalidArgumentException) {
// Base url not found for given langcode.
continue;
}

$url = $link['url'];

if (str_starts_with($url, $baseUrl)) {
Expand Down

0 comments on commit 9ba6229

Please sign in to comment.