Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Catch empty body error (#92)
Browse files Browse the repository at this point in the history
* when statuscode is not 200 throw error with ReasonPhrase

* test for http error with empty body

* remove empty lines

* syntax fix
  • Loading branch information
edwwaarrdd authored and vinkla committed Oct 3, 2018
1 parent 3367499 commit c32b6c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
14 changes: 14 additions & 0 deletions tests/InstagramTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit c32b6c9

Please sign in to comment.