diff options
Diffstat (limited to 'lib/caldav')
-rw-r--r-- | lib/caldav/request/abstract.js | 4 | ||||
-rw-r--r-- | lib/caldav/request/calendar_home.js | 15 | ||||
-rw-r--r-- | lib/caldav/request/errors.js | 49 | ||||
-rw-r--r-- | lib/caldav/sax/dav_response.js | 2 |
4 files changed, 63 insertions, 7 deletions
diff --git a/lib/caldav/request/abstract.js b/lib/caldav/request/abstract.js index 04101b5..41429c6 100644 --- a/lib/caldav/request/abstract.js +++ b/lib/caldav/request/abstract.js @@ -2,7 +2,7 @@ var SAX = ns.require('sax'); var XHR = ns.require('xhr'); - + var Errors = ns.require('request/errors'); /** * Creates an (Web/Cal)Dav request. @@ -69,7 +69,7 @@ self._processResult(req, callback); } else { // fail - callback(new Error('http error code: ' + xhr.status)); + callback(new Errors.CaldavHttpError(xhr.status)); } }); } diff --git a/lib/caldav/request/calendar_home.js b/lib/caldav/request/calendar_home.js index 5ededb5..24b27bc 100644 --- a/lib/caldav/request/calendar_home.js +++ b/lib/caldav/request/calendar_home.js @@ -1,5 +1,7 @@ (function(module, ns) { + var Errors = ns.require('request/errors'); + /** * Creates a propfind request. * @@ -71,8 +73,15 @@ 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)); + } + }); }, @@ -109,7 +118,7 @@ self._findPrincipal(self.url, function(err, url) { if (!url) { - callback(new Error('Cannot resolve principal url')); + callback(err); return; } diff --git a/lib/caldav/request/errors.js b/lib/caldav/request/errors.js new file mode 100644 index 0000000..c3c166e --- /dev/null +++ b/lib/caldav/request/errors.js @@ -0,0 +1,49 @@ +(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')] +)); diff --git a/lib/caldav/sax/dav_response.js b/lib/caldav/sax/dav_response.js index e1218a8..69a4368 100644 --- a/lib/caldav/sax/dav_response.js +++ b/lib/caldav/sax/dav_response.js @@ -134,8 +134,6 @@ '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, |