php-github-api
php-github-api copied to clipboard
ResultPager::get() can return string
Because ResultPager::get() here returns the return value of ResponseMediator::getContent(), it can occasionally return a string, which causes an unhelpful TypeError since it should only ever return an array. Other usages of ResponseMediator::getContent() allow for this, but the ResultPager one does not.
This has been occurring in practice to us so figured I'd raise it here - let me know any other information you need on this issue, it is my first one!
I am getting the same and to add more information, the response that causes this bug is 500 Internal Server Error, the body of the response is empty.
@dangrous or @iwiznia do you have an example call that triggers this behaviour? I would expect that the ErrorPlugin would handle the server error response and throw an exception
It's not any specific request, I am seeing this error pop up "randomly" and if I retry the request, it succeeds. I think it happens whenever it could not contact to the GH servers, thus the 500 error does not contain any data. The PR I submitted to you fixes the problem.
@acrobat - from what I see - there are cases (consistently) where GitHub returns 204 "No Content" i.e. https://api.github.com/repos/tomsausage/empty-public/contributors
E.g. in https://github.com/KnpLabs/php-github-api/blob/4fca25fb5d5be992178b99a0ee8e4395030e89e4/lib/Github/ResultPager.php#L88
// in the (sometimes) valid case that there is no content e.g. getting contributors where there are none
// GitHub seems not to return an empty array, but instead, no content at all
if ($result === "" && $this->client->getLastResponse()->getStatusCode() === 204) {
$result = [];
}
I know there is an existing PR, perhaps checking for this use case specifically? (Might not be 100% of the issue but at least is reproducible.
Will add PR to show what I mean