4 ms·
I've heard a couple of times that requests coming from JS "need to get a 200" in order to see the response data at all. Now, I've never worked with JS myself, b
by ekimekim 12y ago
I've heard a couple of times that requests coming from JS "need to get a 200" in order to see the response data at all. Now, I've never worked with JS myself, but to me this sounds more like a badly-designed library problem, but it keeps becoming an issue every time I push for an API without broken error codes.
- adregan 12y agoThis is not the case with the great library superagent[0], which I can confirm with a little test case I wrote. I have a server that returns a 401 when the Authorization header is missing, but I also like to return a JSON body with a little more information as to what went wrong (ie. the header is flat out missing or the credentials aren't being sent in the correct way, with a link to the documentation), and superagent allows you to output the `response.body` in the `end()` method callback. I think of superagent as the requests[1] of js. In fact, I usually require it under the name requests as they feel so similar. 0: https://github.com/visionmedia/superagent https://github.com/visionmedia/superagent 1: http://docs.python-requests.org/en/latest/ http://docs.python-requests.org/en/latest/ EDIT: link formatting
- deleted 12y ago[deleted]
- rmrfrmrf 12y agoJust looked this up and you're right: in Firefox 3.6, there's a bug where the XMLHttpRequest response body won't be populated by Firefox if the status code is 400. Seems like a little-known bug that has been vaguely referenced elsewhere. http://bugs.jquery.com/ticket/7868 http://bugs.jquery.com/ticket/7868 http://stackoverflow.com/questions/5884286/jquery-ajax-with-non-200-responses http://stackoverflow.com/questions/5884286/jquery-ajax-with-...
- umurkontaci 12y agoThat's a regression from 4 years ago. You can get the response body in any status code in JavaScript.
- umurkontaci 12y agoAll of the commonly used libraries have support for any type of status codes; however, in JS world, you need to have two functions to handle a response, one is for success and one is for error. The developers you have worked with either didn't know that, or was lazy.
- _greim_ 12y ago> requests coming from JS "need to get a 200" I'm not sure what this is, but it could be some sort of expectation where all responses are expected to get a 200 along with wrappers like this: {"status":"error","reason":"not found"} {"status":"success","response":{...}} And client-side devs using jQuery (for example) correspondingly expect to handle error conditions in the "success" callback instead of the "error" callback. When someone used to doing things like the above talks to someone more accustomed to RESTish ways of doing things, quite a bit could get lost in translation and communication often completely breaks down.