Skip to content

Commit

Permalink
Merge pull request #1611 from acdlbs/esri-error-handling
Browse files Browse the repository at this point in the history
Updated esri lookups error handling
  • Loading branch information
alexreisner committed Mar 16, 2023
2 parents 590a61f + 66edfd9 commit ee5cfe6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/geocoder/lookups/esri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,28 @@ def base_query_url(query)
def results(query)
return [] unless doc = fetch_data(query)

if (!query.reverse_geocode?)
return [] if !doc['locations'] || doc['locations'].empty?
end

if (doc['error'].nil?)
if (!query.reverse_geocode?)
return [] if !doc['locations'] || doc['locations'].empty?
end
return [ doc ]
else
return []
case [ doc['error']['code'] ]
when [498]
raise_error(Geocoder::InvalidApiKey, doc['error']['message']) ||
Geocoder.log(:warn, "#{self.name} Geocoding API error: #{doc['error']['message']}")
when [ 403 ]
raise_error(Geocoder::RequestDenied, 'ESRI request denied') ||
Geocoder.log(:warn, "#{self.name} ESRI request denied: #{doc['error']['message']}")
when [ 500 ], [501]
raise_error(Geocoder::ServiceUnavailable, 'ESRI service unavailable') ||
Geocoder.log(:warn, "#{self.name} ESRI service error: #{doc['error']['message']}")
else
raise_error(Geocoder::Error, doc['error']['message']) ||
Geocoder.log(:warn, "#{self.name} Geocoding error: #{doc['error']['message']}")
end
end
return []
end

def query_url_params(query)
Expand Down

0 comments on commit ee5cfe6

Please sign in to comment.