Conversation
JackRyan1989
left a comment
There was a problem hiding this comment.
This looks awesome! I just have a few comments but am happy to approve after that.
|
|
||
| context 'no addresses found by usps' do | ||
| before do | ||
| allow(proofer).to receive(:request_facilities).with(address).and_return(empty_locations) |
There was a problem hiding this comment.
This is nit picky, but it seems like the pattern between this test and the address_controller_spec.rb are different, but essentially doing the same thing. Is there a reason why we're not doing something simple likelet(:addresses) do [] end in address_search_controller.spec.rb?
There was a problem hiding this comment.
i thought it might be a bit easier to read the test like this
There was a problem hiding this comment.
Totally agree. I was more just wondering if there was any value in remaining consistent?
JackRyan1989
left a comment
There was a problem hiding this comment.
Tests pass in dev. Looks good to me!
tomas-nava
left a comment
There was a problem hiding this comment.
I think we're missing AC#4 (first bullet) from LG-8410:
ArcGIS' service returns 200 OK HTTP responses but indicates that there were errors when the response bodies include an "error" key.
I think the right place to capture these is in the find_address_candidates method of ArcgisApi::Geocoder; something like
response = faraday.get(ADDRESS_CANDIDATES_ENDPOINT, params, dynamic_headers) do |req|
req.options.context = { service_name: 'arcgis_geocoder_find_address_candidates' }
end
if response['error_code'].present?
# log an error analytics event
return []
end
return parse_address_candidates(response.body)This is very pseudocodey, because I'm not sure what an error response will look like; I couldn't find good examples in the documentation @allthesignals linked to in the ticket. Maybe you two could pair on this part?
tomas-nava
left a comment
There was a problem hiding this comment.
approve!
I suggested some additional small changes that should be made before merging
| error_code = response_body.dig('error', 'code') | ||
| # response_body is in this format: | ||
| # {"error"=>{"code"=>400, "message"=>"", "details"=>[""]}} | ||
| error_message = response_body.dig('error', 'message') || "Received error code #{error_code}" |
There was a problem hiding this comment.
| error_message = response_body.dig('error', 'message') || "Received error code #{error_code}" | |
| error_code = response_body.dig('error', 'code') | |
| error_message = response_body.dig('error', 'message') || "Received error code #{error_code}" |
This is a mistake I made when I suggested this change... we need to define error_code here.
app/services/arcgis_api/geocoder.rb
Outdated
| response_body, | ||
| RuntimeError.new(error_message), | ||
| { | ||
| status: response_body.dig('error', 'code'), |
There was a problem hiding this comment.
| status: response_body.dig('error', 'code'), | |
| status: error_code, |
...and we can use the variable defined in my last suggestion here
| analytics.idv_arcgis_request_failure( | ||
| api_status_code: 422, | ||
| exception_class: err.class, | ||
| exception_message: err.message, |
There was a problem hiding this comment.
| exception_message: err.message, | |
| exception_message: exception_message, |
| else | ||
| response = proofer.request_pilot_facilities | ||
| end |
There was a problem hiding this comment.
| else | |
| response = proofer.request_pilot_facilities | |
| end | |
| else | |
| response = proofer.request_pilot_facilities | |
| end |
🎫 Ticket
Lg-8410
🛠 Summary of changes
Add analytics event for po search.
Addition in
address_search_controllercalls analytics event for arcgis api when no addresses are found and when errors other thanTimeoutErrorandConnectionFailed.Addition in
usps_locations_controllercalls analytics event for usps api when response successfully returns addresses and when response has no locations.📜 Testing Plan
Provide a checklist of steps to confirm the changes.
10421 Motor City Dr, Bethesda, MD 20817Mile 20 I-83 North, Glen Rock, PA1000 mainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmain boulevard, staten island, massachussetts 10001-12341ArcgisApi::Geocoder.handle_api_errorsto raiseFaraday::TimeoutErrorArcgisApi::Geocoder.handle_api_errorsto raiseFaraday::ConnectionFailed