aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/caldav/http/basic_auth.js3
-rw-r--r--lib/caldav/http/oauth2.js2
-rw-r--r--lib/caldav/request/abstract.js29
-rw-r--r--lib/caldav/xhr.js28
4 files changed, 33 insertions, 29 deletions
diff --git a/lib/caldav/http/basic_auth.js b/lib/caldav/http/basic_auth.js
index 07f083d..5b9f666 100644
--- a/lib/caldav/http/basic_auth.js
+++ b/lib/caldav/http/basic_auth.js
@@ -19,7 +19,8 @@
}
BasicAuth.prototype = {
- __proto__: XHR.prototype
+ __proto__: XHR.prototype,
+ validateStatus: true
};
diff --git a/lib/caldav/http/oauth2.js b/lib/caldav/http/oauth2.js
index 75e6334..8b3b9e5 100644
--- a/lib/caldav/http/oauth2.js
+++ b/lib/caldav/http/oauth2.js
@@ -44,6 +44,8 @@
Oauth2.prototype = {
__proto__: XHR.prototype,
+ validateStatus: true,
+
_sendXHR: function(xhr) {
xhr.setRequestHeader(
'Authorization', 'Bearer ' + this.connection.oauth.access_token
diff --git a/lib/caldav/request/abstract.js b/lib/caldav/request/abstract.js
index 6f33af4..acc91cc 100644
--- a/lib/caldav/request/abstract.js
+++ b/lib/caldav/request/abstract.js
@@ -2,20 +2,6 @@
var SAX = ns.require('sax');
var XHR = ns.require('xhr');
- var Errors = ns.require('errors');
-
- function determineHttpStatusError(status) {
- var message = 'Cannot handle request due to server response';
- var err = 'Unknown';
-
- if (status === 500)
- err = 'ServerFailure';
-
- if (status === 401)
- err = 'Authentication';
-
- return new Errors[err](message);
- }
/**
* Creates an (Web/Cal)Dav request.
@@ -85,19 +71,8 @@
return callback(err);
}
- // handle the success case
- if (xhr.status > 199 && xhr.status < 300) {
- self.sax.close();
- return self._processResult(req, callback);
- }
-
- // probable error cases
- callback(
- determineHttpStatusError(xhr.status),
- xhr
- );
-
-
+ self.sax.close();
+ return self._processResult(req, callback);
});
return req;
diff --git a/lib/caldav/xhr.js b/lib/caldav/xhr.js
index 6c8351f..42e0c32 100644
--- a/lib/caldav/xhr.js
+++ b/lib/caldav/xhr.js
@@ -3,6 +3,7 @@
*/
(function(module, ns) {
var Native;
+ var Errors = ns.require('errors');
if (typeof(window) === 'undefined') {
Native = require('xmlhttprequest').XMLHttpRequest;
@@ -10,6 +11,19 @@
Native = window.XMLHttpRequest;
}
+ function determineHttpStatusError(status) {
+ var message = 'Cannot handle request due to server response';
+ var err = 'Unknown';
+
+ if (status === 500)
+ err = 'ServerFailure';
+
+ if (status === 401)
+ err = 'Authentication';
+
+ return new Errors[err](message);
+ }
+
/**
* Creates a XHR wrapper.
* Depending on the platform this is loaded
@@ -51,6 +65,7 @@
password: null,
url: null,
streaming: true,
+ validateStatus: false,
headers: {},
data: null,
@@ -168,7 +183,18 @@
}
this.waiting = false;
- callback(null, this.xhr);
+
+ if (
+ !this.validateStatus ||
+ (
+ this.xhr.status > 199 &&
+ this.xhr.status < 300
+ )
+ ) {
+ return callback(null, this.xhr);
+ }
+
+ callback(determineHttpStatusError(this.xhr.status), this.xhr);
}
}.bind(this));