Skip to content

Api::decode() fails when parsing result of Request::HEAD request #12

@xmojmr

Description

@xmojmr

The function throws "Decoded JSON is not an array or object." at https://github.com/milo/github-api/blob/v1.4.0/src/Github/Api.php#L257 because the actual value of $contents is "" and it does not match is_array() test neither the is_object() test.

I want to issue a Request::HEAD - style request and call some generic GitHub error handler before running my code. How can I do it? Is behavior of decode() designed or it is just a not-yet covered edge case?

Test case:

$api = new Github\Api();
$response = $api->head("/users");
$decoded = $api->decode($response);

Expected result: $decoded contains some empty value
Actual result: exception is thrown

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions