aboutsummaryrefslogtreecommitdiffstats
path: root/caldav.js
diff options
context:
space:
mode:
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;
}