|
9 | 9 | use Geo\Exception\InconclusiveException; |
10 | 10 | use Geo\Exception\NotAccurateEnoughException; |
11 | 11 | use Geocoder\Exception\CollectionIsEmpty; |
| 12 | +use Geocoder\Exception\InvalidServerResponse; |
12 | 13 | use Geocoder\Location; |
13 | 14 | use Geocoder\Model\AddressCollection; |
14 | 15 | use Geocoder\Provider\GoogleMaps\GoogleMaps; |
15 | 16 | use Geocoder\Query\GeocodeQuery; |
16 | 17 | use Geocoder\Query\ReverseQuery; |
17 | 18 | use Geocoder\StatefulGeocoder; |
18 | 19 | use Locale; |
| 20 | +use RuntimeException; |
19 | 21 |
|
20 | 22 | /** |
21 | 23 | * Geocode via google (UPDATE: api3) |
@@ -140,11 +142,11 @@ public function __construct(array $config = []) { |
140 | 142 | $this->setConfig($config + $defaults); |
141 | 143 |
|
142 | 144 | if ($this->getConfig('locale') === true) { |
143 | | - $this->setConfig('locale', strtolower(Locale::getPrimaryLanguage(I18n::getLocale()))); |
| 145 | + $this->setConfig('locale', strtolower((string)Locale::getPrimaryLanguage(I18n::getLocale()))); |
144 | 146 | } |
145 | 147 |
|
146 | 148 | if ($this->getConfig('region') === true) { |
147 | | - $this->setConfig('region', strtolower(Locale::getRegion(I18n::getLocale()))); |
| 149 | + $this->setConfig('region', strtolower((string)Locale::getRegion(I18n::getLocale()))); |
148 | 150 | } |
149 | 151 | } |
150 | 152 |
|
@@ -189,6 +191,8 @@ public function geocode($address, array $params = []) { |
189 | 191 | $result = $this->geocoder->geocodeQuery(GeocodeQuery::create($address)); |
190 | 192 | } catch (CollectionIsEmpty $e) { |
191 | 193 | throw new InconclusiveException(sprintf('Inconclusive result (total of %s)', 0), 0, $e); |
| 194 | + } catch (InvalidServerResponse $e) { |
| 195 | + throw new RuntimeException(sprintf('Problem with API key `%s`', $this->getConfig('apiKey')) . ': ' . $e->getMessage(), 0, $e); |
192 | 196 | } |
193 | 197 |
|
194 | 198 | if (!$this->_config['allowInconclusive'] && !$this->isConclusive($result)) { |
|
0 commit comments