[GH-ISSUE #59] More graceful way to fail when encountering a non-existing track ID #35

Closed
opened 2026-02-27 19:25:43 +03:00 by kerem · 1 comment
Owner

Originally created by @justin-atp on GitHub (Nov 25, 2016).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/59

When using the method $api->addUserPlaylistTracks() I've been encountering a fatal error whenever there is a non-existing track ID in the array of track IDs. Unfortunately this comes up a lot due to certain tracks being disallowed in certain regions or tracks disappearing over time and it isn't possible to avoid this scenario altogether.

Would it be possible to have this result in a non-fatal warning rather than a fatal error? Stack trace below:

Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: Payload contains a non-existing ID in /src/Request.php:32
Stack trace:
#0 /src/Request.php(189): SpotifyWebAPI\Request->parseBody(Object(stdClass), 400)
#1 /src/Request.php(101): SpotifyWebAPI\Request->send('POST', 'https://api.spo...', '["spotify:track...', Array)
#2 /src/SpotifyWebAPI.php(132): SpotifyWebAPI\Request->api('POST', '/v1/users/someu...', '["spotify:track...', Array)
#3 /index.php(65): SpotifyWebAPI\SpotifyWebAPI->addUserPlaylistTracks('someuser', '6kZaxrc65H4F5T5...', '["spotify:track...')
#4 {main}
  thrown in /src/Request.php on line 32
Originally created by @justin-atp on GitHub (Nov 25, 2016). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/59 When using the method $api->addUserPlaylistTracks() I've been encountering a fatal error whenever there is a non-existing track ID in the array of track IDs. Unfortunately this comes up a lot due to certain tracks being disallowed in certain regions or tracks disappearing over time and it isn't possible to avoid this scenario altogether. Would it be possible to have this result in a non-fatal warning rather than a fatal error? Stack trace below: ``` Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: Payload contains a non-existing ID in /src/Request.php:32 Stack trace: #0 /src/Request.php(189): SpotifyWebAPI\Request->parseBody(Object(stdClass), 400) #1 /src/Request.php(101): SpotifyWebAPI\Request->send('POST', 'https://api.spo...', '["spotify:track...', Array) #2 /src/SpotifyWebAPI.php(132): SpotifyWebAPI\Request->api('POST', '/v1/users/someu...', '["spotify:track...', Array) #3 /index.php(65): SpotifyWebAPI\SpotifyWebAPI->addUserPlaylistTracks('someuser', '6kZaxrc65H4F5T5...', '["spotify:track...') #4 {main} thrown in /src/Request.php on line 32 ```
kerem closed this issue 2026-02-27 19:25:43 +03:00
Author
Owner

@jwilsson commented on GitHub (Nov 25, 2016):

Hmm, I think it's out of the scope for this library to handle these sort of things. It'll throw whenever the HTTP response code is outside 2xx and then it's up to the user to handle it.

If you try/catch the calls you can simply ignore the error if that's what you like.

<!-- gh-comment-id:262957759 --> @jwilsson commented on GitHub (Nov 25, 2016): Hmm, I think it's out of the scope for this library to handle these sort of things. It'll throw whenever the HTTP response code is outside `2xx` and then it's up to the user to handle it. If you `try/catch` the calls you can simply ignore the error if that's what you like.
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#35
No description provided.