aboutsummaryrefslogtreecommitdiffstats
path: root/caldav.js
diff options
context:
space:
mode:
authorMichal Budzynski <michal@virtualdesign.pl>2012-11-09 09:57:53 -0800
committerMichal Budzynski <michal@virtualdesign.pl>2012-11-09 09:57:53 -0800
commit042257fc2db8b1f6afb81ff77bca60c0fd820883 (patch)
tree9d5d3ad9cd66c11e97e7474eb5802992b7596fc9 /caldav.js
parentf7cd3db807b41ca731db7f7cbbbd9d08b595ffe4 (diff)
parentb74223999c5a240306132704177eb9cbb1dc9143 (diff)
downloadjsCalDAV-042257fc2db8b1f6afb81ff77bca60c0fd820883.tar.gz
Merge pull request #6 from michalbe/error-handler
error handler
Diffstat (limited to 'caldav.js')
-rw-r--r--caldav.js72
1 files changed, 64 insertions, 8 deletions
diff --git a/caldav.js b/caldav.js
index 153f2da..a37263e 100644
--- a/caldav.js
+++ b/caldav.js
@@ -2464,8 +2464,6 @@ function write (chunk) {
'DAV:/status': HttpStatusHandler,
'DAV:/resourcetype': ArrayHandler,
'DAV:/current-user-privilege-set': PrivilegeSet,
- 'DAV:/principal-URL': HrefHandler,
- 'DAV:/current-user-principal': HrefHandler,
'urn:ietf:params:xml:ns:caldav/calendar-data': CalendarDataHandler,
'DAV:/value': TextHandler,
'DAV:/owner': HrefHandler,
@@ -2559,9 +2557,58 @@ function write (chunk) {
));
(function(module, ns) {
+ function CaldavHttpError(code) {
+ this.code = code;
+ var message;
+ switch(this.code) {
+ case 401:
+ message = 'Wrong username or/and password';
+ break;
+ case 404:
+ message = 'Url not found';
+ break;
+ case 500:
+ message = 'Server error';
+ break;
+ default:
+ message = this.code;
+ }
+
+ Error.call(this, message);
+ }
+ CaldavHttpError.prototype = {
+ __proto__: Error.prototype,
+ constructor: CaldavHttpError
+ }
+
+ // Unauthenticated error for
+ // Google Calendar
+ function UnauthenticatedError() {
+ var message = "Wrong username or/and password";
+ Error.call(this, message);
+ }
+
+ UnauthenticatedError.prototype = {
+ __proto__: Error.prototype,
+ constructor: UnauthenticatedError
+ }
+
+ module.exports = {
+ CaldavHttpError: CaldavHttpError,
+ UnauthenticatedError: UnauthenticatedError
+ };
+
+}.apply(
+ this,
+ (this.Caldav) ?
+ [Caldav('request/errors'), Caldav] :
+ [module, require('../caldav')]
+));
+(function(module, ns) {
+
var SAX = ns.require('sax');
var XHR = ns.require('xhr');
-
+ var Errors = ns.require('request/errors');
/**
* Creates an (Web/Cal)Dav request.
@@ -2628,7 +2675,7 @@ function write (chunk) {
self._processResult(req, callback);
} else {
// fail
- callback(new Error('http error code: ' + xhr.status));
+ callback(new Errors.CaldavHttpError(xhr.status));
}
});
}
@@ -2941,7 +2988,8 @@ function write (chunk) {
content += this.filter.toString();
}
- return this.template.render(content);
+ var out = this.template.render(content);
+ return out;
}
};
@@ -2956,6 +3004,8 @@ function write (chunk) {
));
(function(module, ns) {
+ var Errors = ns.require('request/errors');
+
/**
* Creates a propfind request.
*
@@ -3027,8 +3077,14 @@ function write (chunk) {
if (!principal) {
principal = findProperty('principal-URL', data, true);
}
-
- callback(null, principal);
+ if ('unauthenticated' in principal) {
+ callback(new Errors.UnauthenticatedError());
+ } else if (principal.href){
+ callback(null, principal.href);
+ } else {
+ callback(new Errors.CaldavHttpError(404));
+ }
+
});
},
@@ -3065,7 +3121,7 @@ function write (chunk) {
self._findPrincipal(self.url, function(err, url) {
if (!url) {
- callback(new Error('Cannot resolve principal url'));
+ callback(err);
return;
}