aboutsummaryrefslogtreecommitdiffstats
path: root/lib/caldav/request/abstract.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/caldav/request/abstract.js')
-rw-r--r--lib/caldav/request/abstract.js30
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/caldav/request/abstract.js b/lib/caldav/request/abstract.js
index 4db3883..6f33af4 100644
--- a/lib/caldav/request/abstract.js
+++ b/lib/caldav/request/abstract.js
@@ -2,7 +2,20 @@
var SAX = ns.require('sax');
var XHR = ns.require('xhr');
- var Errors = ns.require('request/errors');
+ 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.
@@ -72,14 +85,19 @@
return callback(err);
}
+ // handle the success case
if (xhr.status > 199 && xhr.status < 300) {
- // success
self.sax.close();
- self._processResult(req, callback);
- } else {
- // fail
- callback(new Errors.CaldavHttpError(xhr.status));
+ return self._processResult(req, callback);
}
+
+ // probable error cases
+ callback(
+ determineHttpStatusError(xhr.status),
+ xhr
+ );
+
+
});
return req;