From 0be0eac9bb059255df838560df9359c194a37b36 Mon Sep 17 00:00:00 2001 From: Simon Hughesdon Date: Fri, 20 Nov 2020 13:04:44 +0000 Subject: [PATCH] Fix corporate information pages error Some [corporate information pages](https://www.gov.uk/government/organisations/migration-advisory-committee/about) are erroring because the list of IDs in corporate information groups in the details hash doesn't match the list of linked corporate information pages in the links hash. Even if they do eventually resolve, these two lists will occasionally be out of sync when they're updated because of the way our publishing system works. We should defend against this so it doesn't error. Resolves this [sentry error](https://sentry.io/organizations/govuk/issues/1813208304/?environment=production&project=202226&query=is%3Aunresolved&statsPeriod=14d) --- .../content_item/corporate_information_groups.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/presenters/content_item/corporate_information_groups.rb b/app/presenters/content_item/corporate_information_groups.rb index d433a6ee2..951d9bbf4 100644 --- a/app/presenters/content_item/corporate_information_groups.rb +++ b/app/presenters/content_item/corporate_information_groups.rb @@ -61,15 +61,14 @@ def group_title_id(title) end def normalised_group_links(group) - group["contents"].map do |group_item| - normalised_group_item_link(group_item) - end + group["contents"].map { |group_item| normalised_group_item_link(group_item) }.compact end def normalised_group_item_link(group_item) if group_item.is_a?(String) group_item_link = corporate_information_page_links.find { |l| l["content_id"] == group_item } - view_context.link_to(group_item_link["title"], group_item_link["base_path"]) + # it's possible for corporation_information_groups in details and links hashes to be out of sync. + view_context.link_to(group_item_link["title"], group_item_link["base_path"]) if group_item_link else view_context.link_to(group_item["title"], group_item["path"] || group_item["url"]) end