Error on empty response #14

Open
bryanburgers opened this Issue May 26, 2013 · 2 comments

3 participants

@bryanburgers

In Chrome, I get "Syntax Error: Unexpected end of input" when the server returns nothing.

Steps to reproduce:

request({
  ...
  method: "POST",
  json: { my: "data" }
}, ...);

When the server returns a 204, it doesn't return any data with it. However, line 215 tries to parse the empty string as JSON, which causes the error in Chrome.

What is the best way for me to POST some JSON, but expect nothing in return? Using the json key always expects a JSON response from the server?

@ckaatz-here

I have seen the same and it does not make sense for me to try to parse it.

Even i tried to set the Content-Length of the response especially to 0.

@jonathaningram

Could this library not do the JSON.parse call if status code is 204 / no content? Would that be a welcome PR?

@Maistho Maistho referenced this issue in driftyco/ionic-platform-web-client Apr 19, 2016
Closed

browser-request fails on HTTP 204 #94

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