cctmmpeining / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

goog.net.XhrIo.prototype.isSuccess() returns false for some 2xx HTTP status codes #109

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When sending HTTP requests with goog.net.XhrIo, the request will be considered 
failed if 
goog.net.XhrIo.prototype.isSuccess() returns false. Currently, it will only 
return true if the HTTP 
response code is 200, 204 or 304.

Many RESTful services respond with HTTP 201 Created if a POST request is sent 
to create a new 
resource. This leads to the request being considered "failed", which is 
incorrect.

I'd like to propose to following implementation, including all 2xx HTTP status 
codes:

goog.net.XhrIo.prototype.isSuccess = function() {
  switch (this.getStatus()) {
    case 0:         // Used for local XHR requests
    case 200:       // Http Success
    case 201:       // Http Created
    case 202:       // Http Accepted
    case 203:       // Http Non-Authoritative Information
    case 204:       // Http Success - no content
    case 205:       // Http Reset Content
    case 206:       // Http Partial Content
    case 304:       // Http Cache
      return true;

    default:
      return false;
  }
};

Best regards,

Rolf Timmermans

Original issue reported on code.google.com by mol...@gmail.com on 30 Jan 2010 at 1:37

GoogleCodeExporter commented 8 years ago
And the same is true for goog.testing.net.XhrIo.prototype.isSuccess, although I 
wonder why it's not simply 
defined as:

goog.testing.net.XhrIo.prototype.isSuccess = goog.net.XhrIo.prototype.isSuccess;

Best regards,

Rolf Timmermans

Original comment by mol...@gmail.com on 8 Feb 2010 at 7:42

GoogleCodeExporter commented 8 years ago
We just ran into goog.testing.net.XhrIo.prototype.isSuccess being different 
from goog.net.XhrIo.prototype.isSuccess and I found this issue in the tracker.

It looks like the original function seems to have been fixed from when this was 
first reported, but the goog.testing.net.XhrIo function has not.

I added a patch that sets these two functions to be equal.  I wasn't sure how 
best to update the tests however.  Would you like a 202 test that does the same 
thing as the existing testEvents_Success?

Regards,

Dave

Original comment by tilded...@gmail.com on 17 Apr 2012 at 2:02

Attachments: