[GH-ISSUE #279] Dealing with Spotify server not responding exception #206

Closed
opened 2026-02-27 19:26:35 +03:00 by kerem · 5 comments
Owner

Originally created by @upgrader-dev on GitHub (Nov 22, 2024).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/279

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.
image

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.

Originally created by @upgrader-dev on GitHub (Nov 22, 2024). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/279 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. ![image](https://github.com/user-attachments/assets/bf3b97b3-c91e-4161-ad33-d34e33f535a4) 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.
kerem closed this issue 2026-02-27 19:26:36 +03:00
Author
Owner

@jwilsson commented on GitHub (Nov 28, 2024):

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.

<!-- gh-comment-id:2506694223 --> @jwilsson commented on GitHub (Nov 28, 2024): 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.
Author
Owner

@upgrader-dev commented on GitHub (Dec 29, 2024):

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.

<!-- gh-comment-id:2564727249 --> @upgrader-dev commented on GitHub (Dec 29, 2024): 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. >
Author
Owner

@jwilsson commented on GitHub (Jan 13, 2025):

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.

<!-- gh-comment-id:2587621705 --> @jwilsson commented on GitHub (Jan 13, 2025): 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.
Author
Owner

@upgrader-dev commented on GitHub (Apr 6, 2025):

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_

Image

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.

<!-- gh-comment-id:2781603642 --> @upgrader-dev commented on GitHub (Apr 6, 2025): 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_ ![Image](https://github.com/user-attachments/assets/8684ac52-68b0-442b-a6c0-c2c53eb2542a) 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.
Author
Owner

@jwilsson commented on GitHub (Apr 11, 2025):

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.

<!-- gh-comment-id:2796549062 --> @jwilsson commented on GitHub (Apr 11, 2025): 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](https://github.com/jwilsson/spotify-web-api-php/blob/05bb47fde995e619775679c1eb32eeda3f9af6aa/docs/examples/setting-custom-curl-options.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#206
No description provided.