Skip to content

Commit

Permalink
Check exception type
Browse files Browse the repository at this point in the history
This code:
Drupal::requestStack()->getCurrentRequest()?->attributes->get('exception');

returns the raw exception if maintenance mode is enabled, which causes
->getStatusCode() to fail.

This was logged to sentry: https://sentry.hel.fi/organizations/city-of-helsinki/issues/36088.
  • Loading branch information
hyrsky committed Nov 7, 2024
1 parent e280113 commit 4c53409
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use Drupal\menu_link_content\Plugin\Menu\MenuLinkContent;
use Drupal\node\Entity\Node;
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
use Drupal\views\ViewExecutable;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

/**
* Retrieve possible theme color palette override.
Expand Down Expand Up @@ -71,9 +72,7 @@ function hdbt_preprocess_html(&$variables): void {
->getCurrentRequest()?->attributes->get('exception');

// Check if the page is error-page and add class error-page for the body.
if (
$page_status?->getStatusCode() > 400
) {
if ($page_status instanceof HttpExceptionInterface && $page_status->getStatusCode() > 400) {
$variables['attributes']['class'][] = 'error-page';
}

Expand Down

0 comments on commit 4c53409

Please sign in to comment.