Browse Source

Update error handling

pull/2989/head
Manny Dinssa 2 months ago
parent
commit
fe7e3ad987
  1. 14
      app/services/uprn_client.rb

14
app/services/uprn_client.rb

@ -20,13 +20,13 @@ class UprnClient
end end
def result def result
@result ||= begin @result ||= if response.code == 200
parsed_response = JSON.parse(response.body) parsed_response = JSON.parse(response.body)
parsed_response.dig("results", 0, "DPA") || parsed_response.dig("results", 0, "LPI") parsed_response.dig("results", 0, "DPA") || parsed_response.dig("results", 0, "LPI")
rescue JSON::ParserError => e else
Rails.logger.error("Failed to parse JSON response: #{e.message}") Rails.logger.error("Unexpected response code: #{response.code}")
nil nil
end end
end end
private private

Loading…
Cancel
Save