Browse Source

Add error handling for JSON parsing in UPRN client

pull/2989/head
Manny Dinssa 2 months ago
parent
commit
803d31dc9f
  1. 8
      app/services/uprn_client.rb

8
app/services/uprn_client.rb

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

Loading…
Cancel
Save