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

status-code-0-onError-64 #66

Merged
merged 1 commit into from
Feb 6, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fluidinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,16 @@ var fluidinfo = function(options) {
options.data = JSON.stringify(options.data);
}
}
xhr.onerror = function() {
// handle stuff nicely
var result = createNiceResult(xhr);
options.onError(result);
};
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;
var result = createNiceResult(xhr);
// call the event handlers
if (xhr.status > 0 && (xhr.status < 300 || xhr.status == 304)) {
if (xhr.status < 300 || xhr.status == 304) {
if (options.onSuccess){
options.onSuccess(result);
}
Expand Down
30 changes: 0 additions & 30 deletions spec/fluidinfoSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,36 +408,6 @@ describe("Fluidinfo.js", function() {
expect(spy.calledOnce).toBeTruthy();
});

it("should provide a simple response object for onError when the " +
"response status is zero", function() {
var options = new Object();
options.path = "namespaces/test";
var payload = {name: "foo", description: "bar"};
options.data = payload;
var spy = sinon.spy();
options.onError = function(result) {
expect(typeof(result)).toEqual("object");
expect(result.status).toEqual(0);
expect(typeof(result.headers)).toEqual("object");
expect(result.data).toEqual("");
expect(result.rawData).toEqual("");
// original XHR:
expect(typeof(result.request)).toEqual("object");
spy(); // to prove the function was called
};
this.fi.api.post(options);
var responseStatus = 0;
var responseHeaders = {
"Content-Type": "text/html",
"Location": "http://fluiddb.fluidinfo.com/" +
"namespaces/test/foo",
"Date": "Mon, 02 Aug 2010 12:40:41 GMT"};
var responseText = '';
this.server.requests[0].respond(responseStatus, responseHeaders,
responseText);
expect(spy.calledOnce).toBeTruthy();
});

it("should return a simple response object for onSuccess when " +
"async=False", function() {
var options = new Object();
Expand Down