Skip to content

Commit 5d886ef

Browse files
lloy0076freekmurze
authored andcommitted
Check for any error message and throw exception with relevant status. (spatie#34)
1 parent 3728a0e commit 5d886ef

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor
22
composer.phar
33
composer.lock
4+
.idea/

src/Geocoder.php

+8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public function getCoordinatesForAddress(string $address): array
6666

6767
$geocodingResponse = json_decode($response->getBody());
6868

69+
if (!empty($geocodingResponse->error_message)) {
70+
throw new \Exception($geocodingResponse->status);
71+
}
72+
6973
if (! count($geocodingResponse->results)) {
7074
return $this->emptyResponse();
7175
}
@@ -87,6 +91,10 @@ public function getAddressForCoordinates(float $lat, float $lng): array
8791

8892
$reverseGeocodingResponse = json_decode($response->getBody());
8993

94+
if (!empty($reverseGeocodingResponse->error_message)) {
95+
throw new \Exception($reverseGeocodingResponse->status);
96+
}
97+
9098
if (! count($reverseGeocodingResponse->results)) {
9199
return $this->emptyResponse();
92100
}

0 commit comments

Comments
 (0)