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

Error "Payload is set but no content-type header specified" when calling play() #175

Closed
this-username-is-taken opened this issue Jun 16, 2020 · 7 comments
Labels

Comments

@this-username-is-taken
Copy link

this-username-is-taken commented Jun 16, 2020

Describe the bug

I'm seeing an issue where when I call play() without any parameters, I get an exception with the error message "Payload is set but no content-type header specified".

To Reproduce
This reproduces every time I call play(). I am using React Native and reproducing this on an Android phone. Interestingly, I'm only seeing this for play() but not pause(). I also have another project that uses React (instead of React Native) and runs in desktop Chrome and am not observing this issue.

Additional context
Below is the full response returned by Spotify:

{
    "UNSENT": 0,
    "OPENED": 1,
    "HEADERS_RECEIVED": 2,
    "LOADING": 3,
    "DONE": 4,
    "readyState": 4,
    "status": 0,
    "timeout": 0,
    "withCredentials": true,
    "upload": {},
    "_aborted": false,
    "_hasError": true,
    "_method": "PUT",
    "_response": "Payload is set but no content-type header specified",
    "_url": "https://api.spotify.com/v1/me/player/play",
    "_timedOut": false,
    "_trackingName": "unknown",
    "_incrementalEvents": false,
    "_requestId": null,
    "_headers": {
        "authorization": "Bearer BQD1k6iCo2ITQdQTzX6VfGmYwGdeK7rAoAufwi4YDUzJI2EFnENC-q_Z1x2QljnT0TooLJbHUQMn_vKYv5zwig_4ZRWBdboZpFRZ8FuocHBcLMEp-ib-7Ia1r3c8Q87H3Jwu30Hr8ZUr2fOlnx77_w9c2bLIQAAcQW8"
    },
    "_responseType": "",
    "_sent": true,
    "_lowerCaseResponseHeaders": {},
    "_subscriptions": []
}

After some trial and error, I discovered that if I remove the line postData: postData from request.Data in play(), things will work fine:
image

Despite the workaround, I'm still interested in getting to the bottom of this, and hopefully fix it in a non-hacky way if possible.

@this-username-is-taken
Copy link
Author

Seems like a better fix is to add contentType: 'application/json' to requestData.

@JMPerez
Copy link
Owner

JMPerez commented Aug 3, 2020

I think we could add a check on _performRequest() that adds contentType: 'application/json' if the type of params is object and is not null. That's more elegant than adding the contentType to a few functions.

@this-username-is-taken I'll prepare a change, and maybe you can try it out.

@this-username-is-taken
Copy link
Author

Thanks @JMPerez , I can confirm that this is now fixed!

@JMPerez
Copy link
Owner

JMPerez commented Aug 5, 2020

@this-username-is-taken awesome!

@JMPerez JMPerez reopened this Aug 5, 2020
@JMPerez JMPerez closed this as completed Aug 5, 2020
@quentin-sommer
Copy link

Hi,
I don't think the version including this fix (1.5.1) is released: npm
@JMPerez could you release it? I'm having the same issue on react-native

@JMPerez
Copy link
Owner

JMPerez commented Nov 2, 2020

Hi @quentin-sommer, you're right! I have just published 1.5.1

@quentin-sommer
Copy link

Thanks a lot

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

No branches or pull requests

3 participants