mirror of
https://github.com/jwilsson/spotify-web-api-php.git
synced 2026-04-26 23:45:49 +03:00
[GH-ISSUE #269] TypeError when API returns null on getMyCurrentTrack #198
Labels
No labels
bug
docs
enhancement
enhancement
enhancement
feedback wanted
good first issue
help wanted
help wanted
help wanted
invalid
pull-request
question
question
upstream
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotify-web-api-php#198
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @joeygallegos on GitHub (Dec 14, 2023).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/269
I am writing an application that tracks what song I am currently listening to. When I stop playing music and exit the desktop app, I get the below TypeError exception because the API is returning a null response but the function is declared to only allow
array|objectas return types. Right now, when I wrap the code in a try/catch, it doesn't even run the caught exception. When playing music, I get no error.Exception:
I have my code setup like this:
Composer version:
Expectation:
Ideally, when SpotifyAPI returns null because the player is fully exited and the music isn't technically "paused" or "playing", then I should be allowed to check
getMyCurrentTrack()for null value(s) and handle my code based around that.@jwilsson commented on GitHub (Dec 14, 2023):
Hey!
I totally agree, looks like the Spotify docs doesn't reflect reality. The endpoint returns a HTTP 204 with an empty body when nothing is playing which of course will cause
nullto be returned.I'll update the function declaration to reflect this and I've posted on Spotify's developer forum asking them to update the docs.
@jwilsson commented on GitHub (Dec 14, 2023):
And updated function declarations are available in
6.0.2.@joeygallegos commented on GitHub (Dec 14, 2023):
@jwilsson many thanks for fixing the issue! I tried again with the new version, and the issue is resolved. Working as expected.