From 4c53409351266633d1c5b95c34fd8d43b342dfac Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Thu, 7 Nov 2024 15:54:59 +0200 Subject: [PATCH] Check exception type 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. --- hdbt.theme | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hdbt.theme b/hdbt.theme index f7c03acdb..e2ff17dff 100644 --- a/hdbt.theme +++ b/hdbt.theme @@ -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. @@ -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'; }