Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edff171

Browse files
committed
Make sure we check for an error in the reponse
1 parent a5ed4c6 commit edff171

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Geocoder/Provider/Yandex.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ private function executeQuery($query)
100100
$content = (string) $this->getAdapter()->get($query)->getBody();
101101
$json = (array) json_decode($content, true);
102102

103-
if (empty($json) || '0' === $json['response']['GeoObjectCollection']['metaDataProperty']['GeocoderResponseMetaData']['found']) {
103+
if (empty($json) || isset($json['error']) ||
104+
(isset($json['response']) && '0' === $json['response']['GeoObjectCollection']['metaDataProperty']['GeocoderResponseMetaData']['found'])
105+
) {
104106
throw new NoResult(sprintf('Could not execute query "%s".', $query));
105107
}
106108

tests/Geocoder/Tests/Provider/YandexTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testGeocodeWithLocalhostIPv6()
4242
*/
4343
public function testGeocodeWithNull()
4444
{
45-
$provider = new Yandex($this->getMockAdapter());
45+
$provider = new Yandex($this->getMockAdapterReturns('{"error":{"status":"400","message":"missing geocode parameter"}}'));
4646
$provider->geocode(null);
4747
}
4848

@@ -52,7 +52,7 @@ public function testGeocodeWithNull()
5252
*/
5353
public function testGeocodeWithEmpty()
5454
{
55-
$provider = new Yandex($this->getMockAdapter());
55+
$provider = new Yandex($this->getMockAdapterReturns('{"error":{"status":"400","message":"missing geocode parameter"}}'));
5656
$provider->geocode('');
5757
}
5858

0 commit comments

Comments
 (0)