Bug 816306: Part 1 - Report more network errors during update checks. r=bbondy
authorMarshall Culpepper <marshall@mozilla.com>
Thu, 10 Jan 2013 18:10:19 +0100
changeset 118436 64624cab8dc13a6d78d25a8f131c88c4d5746778
parent 118435 9cda648d19fac9cba47833e2415106eba013049a
child 118437 5be4511b8225fbe33e31b584027dd896bb49bbf1
push id24166
push userMs2ger@gmail.com
push dateFri, 11 Jan 2013 13:57:41 +0000
treeherdermozilla-central@63c4b0f66a0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy
bugs816306
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 816306: Part 1 - Report more network errors during update checks. r=bbondy
toolkit/mozapps/update/nsUpdateService.js
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -161,16 +161,19 @@ const WRITE_ERROR_SHARING_VIOLATION_NOPI
 
 
 const CERT_ATTR_CHECK_FAILED_NO_UPDATE  = 100;
 const CERT_ATTR_CHECK_FAILED_HAS_UPDATE = 101;
 const BACKGROUNDCHECK_MULTIPLE_FAILURES = 110;
 const NETWORK_ERROR_OFFLINE             = 111;
 const FILE_ERROR_TOO_BIG                = 112;
 
+// Error codes should be < 1000. Errors above 1000 represent http status codes
+const HTTP_ERROR_OFFSET                 = 1000;
+
 const DOWNLOAD_CHUNK_SIZE           = 300000; // bytes
 const DOWNLOAD_BACKGROUND_INTERVAL  = 600;    // seconds
 const DOWNLOAD_FOREGROUND_INTERVAL  = 0;
 
 const UPDATE_WINDOW_NAME      = "Update:Wizard";
 
 // The number of consecutive failures when updating using the service before
 // setting the app.update.service.enabled preference to false.
@@ -2042,18 +2045,18 @@ UpdateService.prototype = {
   onProgress: function AUS_onProgress(request, position, totalSize) {
   },
 
   onCheckComplete: function AUS_onCheckComplete(request, updates, updateCount) {
     this._selectAndInstallUpdate(updates);
   },
 
   onError: function AUS_onError(request, update) {
-    LOG("UpdateService:onError - error during background update: " +
-        update.statusText);
+    LOG("UpdateService:onError - error during background update. error code: " +
+        update.errorCode + ", status text: " + update.statusText);
 
     var maxErrors;
     var errCount;
     if (update.errorCode == NETWORK_ERROR_OFFLINE) {
       // Register an online observer to try again
       this._registerOnlineObserver();
       return;
     }
@@ -3072,16 +3075,20 @@ Checker.prototype = {
     catch (e) {
     }
 
     if (status == 0)
       status = request.channel.QueryInterface(Ci.nsIRequest).status;
     return status;
   },
 
+  _isHttpStatusCode: function UC__isHttpStatusCode(status) {
+    return status >= 100 && status <= 599;
+  },
+
   /**
    * The XMLHttpRequest succeeded and the document was loaded.
    * @param   event
    *          The nsIDOMEvent for the load
    */
   onLoad: function UC_onLoad(event) {
     LOG("Checker:onLoad - request completed downloading document");
 
@@ -3111,17 +3118,22 @@ Checker.prototype = {
     }
     catch (e) {
       LOG("Checker:onLoad - there was a problem checking for updates. " +
           "Exception: " + e);
       var request = event.target;
       var status = this._getChannelStatus(request);
       LOG("Checker:onLoad - request.status: " + status);
       var update = new Update(null);
+      update.errorCode = status;
       update.statusText = getStatusTextFromCode(status, 404);
+
+      if (this._isHttpStatusCode(status)) {
+        update.errorCode = HTTP_ERROR_OFFSET + status;
+      }
       if (e.result == Cr.NS_ERROR_ILLEGAL_VALUE) {
         update.errorCode = updates[0] ? CERT_ATTR_CHECK_FAILED_HAS_UPDATE
                                       : CERT_ATTR_CHECK_FAILED_NO_UPDATE;
       }
       this._callback.onError(request, update);
     }
 
     this._callback = null;
@@ -3137,20 +3149,24 @@ Checker.prototype = {
     var request = event.target;
     var status = this._getChannelStatus(request);
     LOG("Checker:onError - request.status: " + status);
 
     // If we can't find an error string specific to this status code,
     // just use the 200 message from above, which means everything
     // "looks" fine but there was probably an XML error or a bogus file.
     var update = new Update(null);
+    update.errorCode = status;
     update.statusText = getStatusTextFromCode(status, 200);
+
     if (status == Cr.NS_ERROR_OFFLINE) {
       // We use a separate constant here because nsIUpdate.errorCode is signed
       update.errorCode = NETWORK_ERROR_OFFLINE;
+    } else if (this._isHttpStatusCode(status)) {
+      update.errorCode = HTTP_ERROR_OFFSET + status;
     }
 
     this._callback.onError(request, update);
 
     this._request = null;
   },
 
   /**