-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug/Suggestion] Better Rate Limit Handling #263
Comments
You can (and very likely should) use contexts to achieve the desired behaviour. What I did was something like this: timeoutCtx, cancel := context.WithDeadline(parentCtx, time.Now().Add(30*time.Second))
artist, err := client.GetArtist(timeoutCtx, spotify.ID(event.SpotifyID))
cancel() Then you can handle the error, which - when using withRetry - should be the latest error the client received for this call. If you're very fancy you can then block any request to the Spotify API with the client id/secret combo. In my case I have a global service orchestrating things. I forked and played a bit with this package, exposing the retry-after header, and set a value in redis that marks the Spotify API as "invalid" until a specific RFC339 timestamp. There's sadly no great way around this if you want up-to-date Data in a cached fashion. In my case, I am requesting Spotify's API once every 24 hours for artists my users have interest in to cache them and do some checks (does the artist have a new release, do I need to update their profile picture ect), and once a Month for artists without any interest from my userbase. I still get this issue with just ~10 active test users from time to time due to how much Spotify limits in-development Apps. |
The method with context is not ideal, the program will be blocking for 30 seconds when it could already exit (return error). You can know the time of the |
Situation
During the early stages of development, before getting around to implementing caching & API throttling, I inadvertently triggered a re-render loop on the frontend. This caused an excessive number of requests to the backend, which in turn spammed the Spotify API.
Consequently, my app was suspended for approximately 24 hours and I began receiving the following responses:
Notice that the
retry-after
header is74623
and the response body is not in JSON format as expected. This causeszmb3/spotify
to throw a "spotify: couldn't decode error: (17) [Too many requests]" error.Suggestions
maxWait
(also suggested in Client is (too) quiet if it has to retry #241) or similar mechanism for retries.retry-after
header value so the application can decide how to handle the situation.The text was updated successfully, but these errors were encountered: