Browse Source

Add error handling for JSON parsing in UPRN client (#2989)

* Add error handling for JSON parsing in UPRN client

* Update error handling

* Update error handling 2
pull/2992/head
Manny Dinssa 1 week ago committed by GitHub
parent
commit
d3219b9ba3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/services/uprn_client.rb

9
app/services/uprn_client.rb

@ -20,7 +20,14 @@ class UprnClient
end
def result
@result ||= JSON.parse(response.body).dig("results", 0, "DPA") || JSON.parse(response.body).dig("results", 0, "LPI")
@result ||= if response.is_a?(Net::HTTPSuccess)
parsed_response = JSON.parse(response.body)
parsed_response.dig("results", 0, "DPA") || parsed_response.dig("results", 0, "LPI")
else
Rails.logger.error("Response code: #{response.code}")
Rails.logger.error("Response body: #{response.body}")
nil
end
end
private

Loading…
Cancel
Save