Borks on an HTTP 204 response #160

Closed
jalada opened this Issue Oct 15, 2014 · 12 comments

Projects

None yet

8 participants

@jalada
jalada commented Oct 15, 2014

If the server sends a 204 status code, Reqwest raises an exception:

reqwest("/204") // https://gist.github.com/jalada/fda3dc2d14d05efe97ba

Uncaught TypeError: Cannot read property 'match' of null  reqwest.js:239
  setType                                                 reqwest.js:239
  success                                                 reqwest.js:300
  (anonymous function)                                    reqwest.js:85
@ded
Owner
ded commented Oct 19, 2014

This seems unlikely. I can write a test for it, but could you provide details about the server response

@apoco
apoco commented Oct 25, 2014

Same for responses from HEAD requests. Seems like this library doesn't handle the condition of empty responses.

@apoco
apoco commented Oct 26, 2014

Would this work for a fix? #164

@thomsbg
thomsbg commented Oct 28, 2014

That's right. Responses containing no Content-Type header throw an error inside of setType.

https://github.com/ded/reqwest/blob/master/src/reqwest.js#L233

@ashtuchkin

Just got this exact situation. 204 with no Content-Type => exception.

@rosko
rosko commented Feb 24, 2015

I got the same error. It happens when response contains no "Content-Type" AND request options has no "type" option.
I've just added "type" into request options. And it works.

@okonet
okonet commented Apr 22, 2015

+1

@ded
Owner
ded commented Apr 23, 2015

ok it looks like the PR for the fix it obviously out of date. we should try and get this fix in

@ded ded closed this in 4d4a08e Aug 5, 2015
@odzb
odzb commented Aug 18, 2015

ded, can you please publish the fixed code on npm as 2.0.2? Thank you very much for your work, we depend on it a lot :)

@ded
Owner
ded commented Aug 19, 2015

yikes i forgot to publish

@ded
Owner
ded commented Aug 19, 2015

done!

@odzb
odzb commented Aug 19, 2015

Thank you! One step further would be to put this fix into 1.x (the non-xhr2 version stream) as well.

@desbo desbo added a commit to guardian/frontend that referenced this issue Nov 23, 2015
@desbo desbo Update reqwest to 2.0.5
This includes a fix for a bug where 204 responses were treated as
errors. We need that for the email subscription form in the footer.

See ded/reqwest#160
dd88761
@desbo desbo referenced this issue in guardian/frontend Nov 23, 2015
Merged

Upgrade reqwest to 2.0.5 #11175

1 of 1 task complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment