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

PUT with non-JSON body emits spurious error #66

Closed
rriegs opened this issue Jan 25, 2018 · 1 comment
Closed

PUT with non-JSON body emits spurious error #66

rriegs opened this issue Jan 25, 2018 · 1 comment

Comments

@rriegs
Copy link

rriegs commented Jan 25, 2018

Issuing

$.ajax({
    type: 'PUT',
    url: '/data/abc',
    contentType: 'text/plain',
    data: 'some plain text'
})

results in

> #12 PUT /data/abc

JSON body could not be parsed: Invalid JSON

< #12 200 [+3ms]

If one instead uses data: '"quoted text"', the result is:

> #13 PUT /data/abc

"quoted text"

< #13 200 [+18ms]

and similarly for {"other": "valid JSON"} strings. Note this occurs even if setting contentType: 'text/plain', as shown. The error is purely cosmetic: other operation proceeds as normal. The behavior may have been introduced in #35 in response to #33.

I also note that GET requests print their response data if it is formatted as valid JSON, but otherwise print nothing without error, i.e. they must be checking whether the response is JSON-parsable before attempting to do so. (Actually, it looks like the real distinction is that non-JSON request payloads always cause the error, while response payloads check as appropriate.)

@paulogdm
Copy link
Member

paulogdm commented Mar 16, 2018

Pull request to fix this issue: #74

@rriegs rriegs closed this as completed Aug 28, 2018
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

No branches or pull requests

2 participants