Bug 859058 - Improve error handling; r=jlongster a=kwierso
authorJan Odvarko <odvarko@gmail.com>
Thu, 04 Jun 2015 09:56:47 +0200
changeset 247935 507407471469
parent 247934 e708f2ce973c
child 247936 0935b76b6ec7
push id28887
push userkwierso@gmail.com
push dateThu, 11 Jun 2015 01:10:53 +0000
treeherdermozilla-central@1fd19d8fc936 [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;