Bug 1546606 - Define classes for the various CalDAV response errors. r=Fallen
authorPaul Morris <paul@thunderbird.net>
Thu, 09 Apr 2020 13:52:46 +0300
changeset 38761 11272b25eeab56e35b66cad74023887720bab6f3
parent 38760 1295426fff19b2b7e7da26f0a3d1baf0a295e543
child 38762 7ebcf56c0e59161b0e8dade8311e95d23b38980e
push id401
push userclokep@gmail.com
push dateMon, 01 Jun 2020 20:41:59 +0000
reviewersFallen
bugs1546606
Bug 1546606 - Define classes for the various CalDAV response errors. r=Fallen
calendar/providers/caldav/CalDavCalendar.jsm
calendar/providers/caldav/modules/CalDavRequest.jsm
--- a/calendar/providers/caldav/CalDavCalendar.jsm
+++ b/calendar/providers/caldav/CalDavCalendar.jsm
@@ -1430,17 +1430,17 @@ CalDavCalendar.prototype = {
     }
 
     return args.returnValue;
   },
 
   /**
    * Checks that the calendar URI exists and is a CalDAV calendar. This is the beginning of a
    * chain of asynchronous calls. This function will, when done, call the next function related to
-   * checking resource type, server capabilties, etc.
+   * checking resource type, server capabilities, etc.
    *
    * checkDavResourceType                        * You are here
    * checkServerCaps
    * findPrincipalNS
    * checkPrincipalsNameSpace
    * completeCheckServerInfo
    */
   checkDavResourceType(aChangeLogListener) {
--- a/calendar/providers/caldav/modules/CalDavRequest.jsm
+++ b/calendar/providers/caldav/modules/CalDavRequest.jsm
@@ -292,46 +292,44 @@ class CalDavResponseBase {
   }
 
   /** If the response had an auth error */
   get authError() {
     // 403 is technically "Forbidden", but for our terms it is the same
     return this.status == 401 || this.status == 403;
   }
 
-  /** If the respnse has a conflict code */
+  /** If the response has a conflict code */
   get conflict() {
     return this.status == 409 || this.status == 412;
   }
 
   /** If the response indicates the resource was not found */
   get notFound() {
     return this.status == 404;
   }
 
   /** If the response has a server error (5xx) */
   get serverError() {
     return this.statusCategory == 5;
   }
 
   /**
-   * Raise an exception if one of the handled 4xx and 5xx occured
+   * Raise an exception if one of the handled 4xx and 5xx occured.
    */
   raiseForStatus() {
-    /* eslint-disable no-undef */
     if (this.authError) {
       throw new HttpUnauthorizedError(this);
     } else if (this.conflict) {
       throw new HttpConflictError(this);
     } else if (this.notFound) {
       throw new HttpNotFoundError(this);
     } else if (this.serverError) {
       throw new HttpServerError(this);
     }
-    /* eslint-enable no-undef */
   }
 
   /** The text response of the request */
   get text() {
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   }
 
   /** @return {DOMDocument} A DOM document with the response xml */
@@ -358,16 +356,56 @@ class CalDavResponseBase {
       return this.nsirequest.getResponseHeader(aHeader);
     } catch (e) {
       return null;
     }
   }
 }
 
 /**
+ * Thrown when the response had an authorization error (status 401 or 403).
+ */
+class HttpUnauthorizedError extends Error {
+  constructor(message) {
+    super(message);
+    this.name = "HttpUnauthorizedError";
+  }
+}
+
+/**
+ * Thrown when the response has a conflict code (status 409 or 412).
+ */
+class HttpConflictError extends Error {
+  constructor(message) {
+    super(message);
+    this.name = "HttpConflictError";
+  }
+}
+
+/**
+ * Thrown when the response indicates the resource was not found (status 404).
+ */
+class HttpNotFoundError extends Error {
+  constructor(message) {
+    super(message);
+    this.name = "HttpNotFoundError";
+  }
+}
+
+/**
+ * Thrown when the response has a server error (status 5xx).
+ */
+class HttpServerError extends Error {
+  constructor(message) {
+    super(message);
+    this.name = "HttpServerError";
+  }
+}
+
+/**
  * A simple caldav response using nsIStreamLoader
  */
 class CalDavSimpleResponse extends CalDavResponseBase {
   QueryInterface(aIID) {
     return cal.generateClassQI(this, aIID, [Ci.nsIStreamLoaderObserver]);
   }
 
   get listener() {