Bug 1553995 - Remote Settings should not throw with dummy server r=glasserc,Gijs
authorMathieu Leplatre <mathieu@mozilla.com>
Fri, 31 May 2019 09:53:05 +0000
changeset 476352 922159dfca4ed9ac4fc2249be5843693481ecb01
parent 476351 27e7793c61a11b96fb854da61830ff785203df64
child 476353 858d04f452e2d4344a79dd83dc49749c41162c7e
push id36092
push userarchaeopteryx@coole-files.de
push dateFri, 31 May 2019 17:03:46 +0000
treeherdermozilla-central@8384972e1f6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglasserc, Gijs
bugs1553995
milestone69.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 1553995 - Remote Settings should not throw with dummy server r=glasserc,Gijs Differential Revision: https://phabricator.services.mozilla.com/D32549
services/settings/Utils.jsm
services/settings/test/unit/test_remote_settings_poll.js
--- a/services/settings/Utils.jsm
+++ b/services/settings/Utils.jsm
@@ -97,32 +97,33 @@ var Utils = {
     if (params) {
       url += "?" + Object.entries(params).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join("&");
     }
     const response = await fetch(url, { headers });
 
     let changes = [];
     // If no changes since last time, go on with empty list of changes.
     if (response.status != 304) {
+      const is404FromCustomServer = response.status == 404 && Services.prefs.prefHasUserValue("services.settings.server");
+
       const ct = response.headers.get("Content-Type");
-      if (!ct || !ct.includes("application/json")) {
+      if (!is404FromCustomServer && (!ct || !ct.includes("application/json"))) {
         throw new Error(`Unexpected content-type "${ct}"`);
       }
       let payload;
       try {
         payload = await response.json();
       } catch (e) {
         payload = e.message;
       }
 
       if (!payload.hasOwnProperty("data")) {
         // If the server is failing, the JSON response might not contain the
         // expected data. For example, real server errors (Bug 1259145)
         // or dummy local server for tests (Bug 1481348)
-        const is404FromCustomServer = response.status == 404 && Services.prefs.prefHasUserValue("services.settings.server");
         if (!is404FromCustomServer) {
           throw new Error(`Server error ${response.status} ${response.statusText}: ${JSON.stringify(payload)}`);
         }
       } else {
         changes = payload.data;
       }
     }
     // The server should always return ETag. But we've had situations where the CDN
--- a/services/settings/test/unit/test_remote_settings_poll.js
+++ b/services/settings/test/unit/test_remote_settings_poll.js
@@ -448,17 +448,17 @@ add_task(async function test_server_bad_
   };
   checkUptakeTelemetry(startHistogram, endHistogram, expectedIncrements);
 });
 add_task(clear_state);
 
 
 add_task(async function test_server_404_response() {
   function simulateDummy404(request, response) {
-    response.setHeader("Content-Type", "application/json; charset=UTF-8");
+    response.setHeader("Content-Type", "text/html; charset=UTF-8");
     response.write("<html></html>");
     response.setStatusLine(null, 404, "OK");
   }
   server.registerPathHandler(CHANGES_PATH, simulateDummy404);
 
   await RemoteSettings.pollChanges(); // Does not fail when running from tests.
 });
 add_task(clear_state);