Dealing with Spotify server not responding exception
Closed this issue · 5 comments
Hello guys,
My app is currently in dev mode under my developer.spotify account.
Sometimes it happens that Spotify'servers no more respond to my requests, I guess that may be because I get out of my quota.
This kind of exception is not caught by SpotifyWebApiException because it is not :)
Have a look at the screen shot.

So I'm wondering... How do you guys deal with such exceptions?
My first thought was to wrap every request to SpotifyWebAPI in a try catch but wouldn't it be easier that the wrapper itself deals with this kind of exception?
More a discussion than an issue, but didn't find any discussion tab here.
Thank you for your help.
Hello!
I don't think the API will just timeout if you hit your quota, it should reply with a HTTP 429 error which you can have the library automatically retry.
I'm a bit confused if that's actually the error though or if it's something else causing your script to exceed the 30 second limit, you could try setting the cURL timeout to a lower value and see if the same issue occurs.
Because I'm not sure what the library would do with any timeout errors otherwise either, I think the thing that would make the most sense in that case it to just re-throw the error which would still need to be handled by the calling code.
Hmm, that sounds strange though 🤔
But my thinking with lowering the request timeout was due to the error message in your screenshot, the PHP execution limit is reached which isn't something library can do much about.
Got a new happen of this behaviour today.
_Fatal error: Maximum execution time of 30 seconds exceeded in /app/vendor/jwilsson/spotify-web-api-php/src/Request.php on line 225
Warning: Cannot modify header information - headers already sent by (output started at /app/vendor/jwilsson/spotify-web-api-php/src/Request.php:225) in /app/vendor/symfony/http-foundation/Session/SessionUtils.php on line 52_
Wouldn't this exception be caught by your code? Or Do I have to catch it? Personnaly I would initially believe it would throw a SpotifyWebAPIException.
It seems the Spotify API is taking too long to respond so the server is killing the PHP process. This isn't something the library can (or should) handle.
I'd limit the request timeout so the request will fail with an expected SpotifyWebAPIException before 30 seconds has elapsed and the server kills it. There's some docs on how to accomplish that here.
