zmb3 / spotify

A Go wrapper for the Spotify Web API
Apache License 2.0
1.39k stars 291 forks source link

PlayerCurrentlyPlaying() returns error EOF when nothing is playing #109

Closed Nikos410 closed 4 years ago

Nikos410 commented 4 years ago

Hi there!

I noticed that the function client.PlayerCurrentlyPlaying() returns an error with the message EOF when no song is currently playing.

The error occurs when trying to decode an empty response body.

if result != nil {
    if err := json.NewDecoder(resp.Body).Decode(result); err != nil {
        return err
    }
}

Debugger Screenshot

I would offer to submit a PR to fix this, but this is actually the first project I'm working on using go, so I'm not sure how to approach this issue.

Thanks!

zmb3 commented 4 years ago

Hey there, thanks for the issue.

This looks to be a duplicate of #72, which should have been fixed by #88, but it looks like we only made the 204 check in *Client.get() and not in *Client.execute().

As I look at get and execute I spot other subtle differences as well (retry logic, error decoding, etc).

It looks like we need to make a similar if resp.StatusCode == http.StatusNoContent check in execute so that get and execute behave the same. At that point, we might as well do away with the get helper and just use execute everywhere to avoid having to maintain such similar methods.