Skip to content

Commit

Permalink
UPRN now accepts errors from the API upon being invalid. New issue sp…
Browse files Browse the repository at this point in the history
…otted to be fixed next where a blank UPRN will result in a 404 unknown path
  • Loading branch information
Felixim0 committed Nov 4, 2024
1 parent ee0fc3e commit 2b54e62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ def page_specific_input_error(
):
endpoints = get_endpoints(called_from=page_name_with_error)
page_location = get_page_location(
endpoints, page_name_with_error) # I.e. singlesearch's location
searchable_fields = get_fields('singlesearch')
endpoints, page_name_with_error)
# Get the fields that are on the page with the error
searchable_fields = get_fields(page_name_with_error)

# Knowing the error from the API, get the databasename of the feild that matches the error
name_of_broken_field = match_api_error_message_to_name_of_field(
primary_error_message)

# Loop through all fields and find the one that matches the name of the broken field
# Loop through all fields on the page, set it's "error_message" to the primary_error_message from the API
for field in searchable_fields:
if field.database_name == name_of_broken_field:
field.error_message = primary_error_message
Expand All @@ -42,3 +44,5 @@ def match_api_error_message_to_name_of_field(primary_error_message):
return 'epoch'
if 'Limit parameter is ' in primary_error_message:
return 'limit'
if 'UPRNs must be numeric' in primary_error_message:
return 'uprn'
2 changes: 1 addition & 1 deletion src/aims_ui/page_helpers/error/error_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def error_page_api_response(page_name, user_input, result):
],
)

if status_code == 400:
if int(status_code) == 400:
log_err(page_name, user_input, f'Bad Request Error: "{clean_result}"')
# TODO Decide here if it's got additional feedback for a specific input
# TODO if not, then return a service error page
Expand Down

0 comments on commit 2b54e62

Please sign in to comment.