Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/google_maps_service/apis/directions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ def directions(origin, destination,
return get('/maps/api/directions/json', params)[:routes]
end
end
end
end
4 changes: 3 additions & 1 deletion lib/google_maps_service/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,11 @@ def check_body_error(response, body)
raise GoogleMapsService::Error::RequestDeniedError.new(response), body[:error_message]
when 'INVALID_REQUEST'
raise GoogleMapsService::Error::InvalidRequestError.new(response), body[:error_message]
when 'NOT_FOUND'
raise GoogleMapsService::Error::NotFoundError.new(response), (body[:error_message] || 'ADDRESS NOT FOUND')
else
raise GoogleMapsService::Error::ApiError.new(response), body[:error_message]
end
end
end
end
end
6 changes: 5 additions & 1 deletion lib/google_maps_service/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ class RateLimitError < ApiError
# An unathorized error occurred. It might be caused by invalid key/secret or invalid access.
class RequestDeniedError < ApiError
end

# When an Address is not found. i.e. An address string could not be geocoded
class NotFoundError < ApiError
end
end
end
end
14 changes: 13 additions & 1 deletion spec/google_maps_service/apis/directions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
end
end

context 'unparseable / non-existing address' do
before(:example) do
stub_request(:get, /https:\/\/maps.googleapis.com\/maps\/api\/directions\/.*/)
.to_return(:status => 200, headers: { 'Content-Type' => 'application/json' }, body: '{"results": [], "status": "NOT_FOUND"}')
end

it 'should raise GoogleMapsService::Error::NotFoundError' do
expect { client.directions('dsfdsfdsfdsfdsfadsfdrcgtzvhstrvzstrhstrgcrscgtr', 'Sydney Town Hall',
mode: 'driving') }.to raise_error GoogleMapsService::Error::NotFoundError
end
end

context 'travel mode round trip' do
it 'should call Google Maps Web Service' do
routes = client.directions('Town Hall, Sydney', 'Parramatta, NSW',
Expand Down Expand Up @@ -146,4 +158,4 @@
expect(a_request(:get, 'https://maps.googleapis.com/maps/api/directions/json?origin=Sydney+Town+Hall&destination=Parramatta+Town+Hall&alternatives=true&key=%s' % api_key)).to have_been_made
end
end
end
end