Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle errors from Elections API #4596

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

unoduetre
Copy link
Contributor

@unoduetre unoduetre commented Jan 17, 2025

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

What

The postcode lookup tool on https://www.gov.uk/contact-electoral-registration-office uses the Electoral Commisions' Elections API to match postcodes to Registration Offices. Sometimes their API goes down, and as a result when a user searches for a postcode on this page, instead of them seeing a result, they will be show a standard gov.uk 500 error page.

This card is about adding some error handling to Frontend so that:

  • the error is sent to sentry
  • a more useful message is show to the user instead

Why

Trello card

Screenshots

Screenshot 2025-01-17 at 09-46-50 Error Contact your Electoral Registration Office - GOV UK

@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4596 January 17, 2025 09:30 Inactive
@unoduetre unoduetre force-pushed the 3159-gracefully-handle-errors-from-elections-api-1 branch from ee41a0e to ea0bb4d Compare January 17, 2025 09:38
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4596 January 17, 2025 09:39 Inactive
else
raise
end
end

def request_url
endpoint = postcode.present? ? "postcode/#{postcode}" : "address/#{uprn}"
"#{api_base_path}/#{endpoint}?token=#{ENV['ELECTIONS_API_KEY']}"
"#{api_base_path}/#{endpoint}?token=#{api_key}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small refactoring.

@@ -3,31 +3,43 @@
# not the values of them. This is because LocationError is a bit odd,
# and it might be worth refactoring the actual code after the RSpec
# conversion is finished.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some refactoring here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants