Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startOrResume throws error code 400 (malformed json) #185

Closed
adamkoch opened this issue Dec 1, 2023 · 5 comments · Fixed by #210
Closed

startOrResume throws error code 400 (malformed json) #185

adamkoch opened this issue Dec 1, 2023 · 5 comments · Fixed by #210

Comments

@adamkoch
Copy link

adamkoch commented Dec 1, 2023

When I call startOrResume() I am getting error 400:

flutter: Error Code: 400
Malformed json
flutter: 
#0      SpotifyApiBase.handleErrors (package:spotify/src/spotify_base.dart:238:7)
#1      SpotifyApiBase._requestWrapper (package:spotify/src/spotify_base.dart:212:16)
<asynchronous suspension>
#2      SpotifyApiBase._putImpl (package:spotify/src/spotify_base.dart:201:12)
<asynchronous suspension>
#3      PlayerEndpoint.startOrResume (package:spotify/src/endpoints/player.dart:97:5)
<asynchronous suspension>
#4      _SpotifyScreenState._buildSpotifyConnected.<anonymous closure> (package:my_app/screens/spotify.dart:192:23)
<asynchronous suspension>

Is there a way to turn on debug logging so I can see the actual http requests being sent out and see what the issue is with the request?

Additional info:

@adamkoch
Copy link
Author

adamkoch commented Dec 1, 2023

I used Flutter DevTools to inspect the network requests and it appears all fine. It's sending a simple PUT request to:
https://api.spotify.com/v1/me/player/play?

Comparing to the sample request in the Spotify docs it looks the same AFAICT. I kept the request body empty for both of them.

@hayribakici
Copy link
Collaborator

hayribakici commented Dec 1, 2023

@adamkoch So far there are no debug tools in this library. However, this is a good idea. I'll create another issue for this.

@adamkoch
Copy link
Author

To follow up, I found the issue was that:
.player.startOrResume()

Adds an empty request body of "". Which Spotify considers a malformed request which is why it's not working. I looked over the code but couldn't find where to have it return an empty body when there are no parameters supplied. If you have any code pointers please let me know.

@adamkoch
Copy link
Author

Perhaps here, default is to set body to empty string vs null:
https://github.com/rinukkusu/spotify-dart/blob/v0.11.0/lib/src/spotify_base.dart#L167

@rinukkusu
Copy link
Owner

Fix is released with v0.13.4!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants