adamint / spotify-web-api-kotlin

Spotify Web API wrapper for Kotlin, Java, JS, and Native - Targets JVM, Android, JS (browser), Native (Desktop), and Apple tvOS/iOS. Includes a Spotify Web Playback SDK wrapper for Kotlin/JS, and a spotify-auth wrapper for Kotlin/Android.
https://adamint.github.io/spotify-web-api-kotlin-docs/
MIT License
194 stars 21 forks source link

Infinite retry loop when receiving status code 204 #312

Closed Nielssg closed 2 years ago

Nielssg commented 2 years ago

Describe the bug Recently in #305 a method has been added to return null when the Spotify API returns a 204 status. I found out that the library keeps retrying when it has found a 204 status code, instead of plainly returning null.

In the execute() method in the Endpoints.kt file, at line 134, we see that the API delegates the response handling (handleResponse), but also defaults to executing the method again when the result of that response handling is null. In the recent issue, a check has been added to the handleResponse() method which will return null if the status code is 204. This, however, triggers a retry due to the handleResponse(bla bla ..) ?: execute(bla bla ..).

To Reproduce Steps to reproduce the behavior:

  1. Make sure to not use Spotify for a while, the 204 will occur if Spotify detects that you are not using it for a period of time
  2. Use the getCurrentContext method (spotifyClientAPI?.player?.getCurrentContext() to get the current playback state
  3. Setting breakpoints in the execute method of Endpoints.kt, you'll notice the retries

Expected behavior Execute method should just return null instead of continously retry

Screenshots image

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context