diff --git a/src/Instagram.php b/src/Instagram.php index e811f94..29f0724 100644 --- a/src/Instagram.php +++ b/src/Instagram.php @@ -119,6 +119,10 @@ protected function get(string $path): object throw new InstagramException($body->meta->error_message); } + if ($response->getStatusCode() !== 200) { + throw new InstagramException($response->getReasonPhrase()); + } + return $body; } } diff --git a/tests/InstagramTest.php b/tests/InstagramTest.php index 3516276..8d7dbc3 100644 --- a/tests/InstagramTest.php +++ b/tests/InstagramTest.php @@ -66,4 +66,18 @@ public function testError() (new Instagram('imspeechlessihavenospeech'))->media(); } + + public function testHttpError() + { + $this->expectException(InstagramException::class); + $this->expectExceptionMessage('No server is available for the request'); + + $response = new Response(503, [], null, null, 'No server is available for the request'); + + $client = new Client(); + $client->addResponse($response); + + $instagram = new Instagram('jerryseinfeld', $client); + $user = $instagram->self(); + } }