zmb3 / spotify

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

HTTP 204 for Client.PlayerStateOpt() #87

Closed joelterry closed 5 years ago

joelterry commented 5 years ago

From previous issues, it looks like the HTTP 204 error has already been dealt with when it comes to playback functions, but I'm currently getting it for Client.PlayerStateOpt().

Simply substituting Client.get() with Client.execute() in Client.PlayerStateOpt() won't work, as it will result in an EOF error when reading the Body on a 204.

Since HTTP 204 seems to be a standard part of Spotify's API, could we add a check to Client.get() before decoding the Body that returns nil if the status code is 204?

Alternatively, if you don't want to mess with the Client.get() code, returning an exported error type that includes the HTTP status code would be nice.

zmb3 commented 5 years ago

Happy to review a PR with these changes.

Simply substituting Client.get() with Client.execute() in Client.PlayerStateOpt() won't work, as it will result in an EOF error when reading the Body on a 204.

It shouldn't attempt to read the body if you pass in a nil result, right?

joelterry commented 5 years ago

Thank you! And yes, but I want to read the body if I don't get a 204 is the problem. I'm assuming the previous cases for playback functions were always 204, but player state can give 200 or 204 depending on if anything is returned.

voldemortensen commented 5 years ago

Just hit the same issue. It seems the me/player endpoint changed, as the docs say it should return a 200 with no content. See https://github.com/spotify/web-api/issues/1158#issuecomment-461983646