Skip to content

Commit

Permalink
catch resolver failure due to bad URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Oct 31, 2024
1 parent 0b831b4 commit 7102129
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions judgments/templatetags/navigation_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import template
from django.urls import resolve
from django.urls import Resolver404, resolve

register = template.Library()

Expand All @@ -8,7 +8,12 @@
def navigation_item_class(context, path):
request = context.get("request")

if request and resolve(request.path_info).url_name == path:
try:
request_path = resolve(request.path_info).url_name
except Resolver404:
request_path = None

if request and request_path and request_path == path:
return "govuk-header__navigation-item govuk-header__navigation-item--active"

return "govuk-header__navigation-item"

0 comments on commit 7102129

Please sign in to comment.