Skip to content

Commit dc518d2

Browse files
committed
More clear exception.
1 parent 08d4872 commit dc518d2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Geocoder/Geocoder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
use Geo\Exception\InconclusiveException;
1010
use Geo\Exception\NotAccurateEnoughException;
1111
use Geocoder\Exception\CollectionIsEmpty;
12+
use Geocoder\Exception\InvalidServerResponse;
1213
use Geocoder\Location;
1314
use Geocoder\Model\AddressCollection;
1415
use Geocoder\Provider\GoogleMaps\GoogleMaps;
1516
use Geocoder\Query\GeocodeQuery;
1617
use Geocoder\Query\ReverseQuery;
1718
use Geocoder\StatefulGeocoder;
1819
use Locale;
20+
use RuntimeException;
1921

2022
/**
2123
* Geocode via google (UPDATE: api3)
@@ -140,11 +142,11 @@ public function __construct(array $config = []) {
140142
$this->setConfig($config + $defaults);
141143

142144
if ($this->getConfig('locale') === true) {
143-
$this->setConfig('locale', strtolower(Locale::getPrimaryLanguage(I18n::getLocale())));
145+
$this->setConfig('locale', strtolower((string)Locale::getPrimaryLanguage(I18n::getLocale())));
144146
}
145147

146148
if ($this->getConfig('region') === true) {
147-
$this->setConfig('region', strtolower(Locale::getRegion(I18n::getLocale())));
149+
$this->setConfig('region', strtolower((string)Locale::getRegion(I18n::getLocale())));
148150
}
149151
}
150152

@@ -189,6 +191,8 @@ public function geocode($address, array $params = []) {
189191
$result = $this->geocoder->geocodeQuery(GeocodeQuery::create($address));
190192
} catch (CollectionIsEmpty $e) {
191193
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);
192196
}
193197

194198
if (!$this->_config['allowInconclusive'] && !$this->isConclusive($result)) {

0 commit comments

Comments
 (0)