aboutsummaryrefslogtreecommitdiffstats
path: root/lib/caldav/request/abstract.js
diff options
context:
space:
mode:
authorKevin Grandon <kevingrandon@yahoo.com>2013-05-07 12:02:48 -0700
committerKevin Grandon <kevingrandon@yahoo.com>2013-05-07 12:02:48 -0700
commit9b5dd29c45ea08ff362198ffb984492df1ebadb1 (patch)
tree0d48aca900256baf82f0aa599d455a978780fa19 /lib/caldav/request/abstract.js
parentc81e925aa6dada192db75dccd4287ab1e9e09ab2 (diff)
parent0b4733ebb28368198b747079d51033a7eeb1f276 (diff)
downloadjsCalDAV-9b5dd29c45ea08ff362198ffb984492df1ebadb1.tar.gz
Merge pull request #15 from lightsofapollo/error-refactoring
Initial error refactoring (make errors less HTTP specific)
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;