Bug 859058 - Improve error handling; r=jlongster a=kwierso
authorJan Odvarko <odvarko@gmail.com>
Thu, 04 Jun 2015 09:56:47 +0200
changeset 248050 507407471469d02585269adefd82421362e909b9
parent 248049 e708f2ce973c781aad13a0b7b61ef8b913e78bf6
child 248051 0935b76b6ec725b26d5195d74b6b7d9bdc175d6a
push id60888
push userkwierso@gmail.com
push dateThu, 11 Jun 2015 01:38:38 +0000
treeherdermozilla-inbound@39e638ed06bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlongster, kwierso
bugs859058
milestone41.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 859058 - Improve error handling; r=jlongster a=kwierso
browser/devtools/netmonitor/har/har-exporter.js
--- a/browser/devtools/netmonitor/har/har-exporter.js
+++ b/browser/devtools/netmonitor/har/har-exporter.js
@@ -112,16 +112,22 @@ const HarExporter = {
       Services.prefs.getBoolPref("devtools.netmonitor.har.includeResponseBodies");
     options.jsonpCallback = options.jsonpCallback ||
       Services.prefs.getCharPref( "devtools.netmonitor.har.jsonpCallback");
     options.forceExport = options.forceExport ||
       Services.prefs.getBoolPref("devtools.netmonitor.har.forceExport");
 
     // Build HAR object.
     return this.buildHarData(options).then(har => {
+      // Do not export an empty HAR file, unless the user
+      // explicitly says so (using the forceExport option).
+      if (!har.log.entries.length && !options.forceExport) {
+        return resolve();
+      }
+
       let jsonString = this.stringify(har);
       if (!jsonString) {
         return resolve();
       }
 
       // If JSONP is wanted, wrap the string in a function call
       if (options.jsonp) {
         // This callback name is also used in HAR Viewer by default.
@@ -138,32 +144,19 @@ const HarExporter = {
 
   /**
    * Build HAR data object. This object contains all HTTP data
    * collected by the Network panel. The process is asynchronous
    * since it can involve additional RDP communication (e.g. resolving
    * long strings).
    */
   buildHarData: function(options) {
-    let deferred = defer();
-
-    try {
-      // Build HAR object from provided data.
-      let builder = new HarBuilder(options);
-      builder.build().then(har => {
-        if (!har.log.entries.length && !options.forceExport) {
-          deferred.resolve();
-        }
-        deferred.resolve(har);
-      });
-    } catch (err) {
-      deferred.reject(err);
-    }
-
-    return deferred.promise;
+    // Build HAR object from collected data.
+    let builder = new HarBuilder(options);
+    return builder.build();
   },
 
   /**
    * Build JSON string from the HAR data object.
    */
   stringify: function(har) {
     if (!har) {
       return null;