|
15 | 15 | use Geocoder\Collection; |
16 | 16 | use Geocoder\Exception\InvalidArgument; |
17 | 17 | use Geocoder\Exception\InvalidCredentials; |
| 18 | +use Geocoder\Exception\InvalidServerResponse; |
| 19 | +use Geocoder\Exception\QuotaExceeded; |
18 | 20 | use Geocoder\Exception\UnsupportedOperation; |
19 | 21 | use Geocoder\Http\Provider\AbstractHttpProvider; |
20 | 22 | use Geocoder\Location; |
|
27 | 29 | use Geocoder\Query\ReverseQuery; |
28 | 30 | use Geocoder\Provider\Provider; |
29 | 31 | use Http\Client\HttpClient; |
| 32 | +use Psr\Http\Message\ResponseInterface; |
30 | 33 |
|
31 | 34 | /** |
32 | 35 | * @author William Durand <william.durand1@gmail.com> |
@@ -394,4 +397,23 @@ private function mapBoundsToArray(Bounds $bounds) |
394 | 397 | 'lr' => [static::KEY_LAT => $bounds->getSouth(), static::KEY_LNG => $bounds->getEast()], |
395 | 398 | ]; |
396 | 399 | } |
| 400 | + |
| 401 | + protected function parseHttpResponse(ResponseInterface $response, string $url): string |
| 402 | + { |
| 403 | + $statusCode = $response->getStatusCode(); |
| 404 | + if (401 === $statusCode || 403 === $statusCode) { |
| 405 | + throw new InvalidCredentials(); |
| 406 | + } elseif (429 === $statusCode) { |
| 407 | + throw new QuotaExceeded(); |
| 408 | + } elseif ($statusCode >= 300) { |
| 409 | + throw InvalidServerResponse::create($url, $statusCode); |
| 410 | + } |
| 411 | + |
| 412 | + $body = (string)$response->getBody(); |
| 413 | + if (empty($body)) { |
| 414 | + throw InvalidServerResponse::emptyResponse($url); |
| 415 | + } |
| 416 | + |
| 417 | + return $body; |
| 418 | + } |
397 | 419 | } |
0 commit comments