Dealing with Spotify server not responding exception
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.
Hello,
In fact I never get any 429 response in many month of work. But sometimes When I get a lot if users on my app this behavior happens. That’s why I end up thinking that the API never sends the 429 response while stated in the documentation. That wouldn’t be the first behavior being note like in the docs :)
Did you already get any 429?
I read carefully the end of your answer below but can’t understand why lowering the timeout limit may be useful.
I’ll try to get this error reproduced and if needed I’ll update this subject :)
Thank you
Benjamin
Le 28 nov. 2024 à 20:45, Jonathan Wilsson @.*** @.***>> a écrit :
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 https://github.com/jwilsson/spotify-web-api-php/blob/05bb47fde995e619775679c1eb32eeda3f9af6aa/docs/examples/setting-options.md#auto_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 https://github.com/jwilsson/spotify-web-api-php/blob/05bb47fde995e619775679c1eb32eeda3f9af6aa/docs/examples/setting-custom-curl-options.md 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.
— Reply to this email directly, view it on GitHub https://github.com/jwilsson/spotify-web-api-php/issues/279#issuecomment-2506694223, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2YPLLYSU3GTSL7UNWN2MVL2C5XD5AVCNFSM6AAAAABSI65F6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBWGY4TIMRSGM. You are receiving this because you authored the thread.
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.