Display error if TFTP post fails

Display an error if the DownloadViaTFTP returns an
error code. This code replaces some unused code.

Resolves openbmc/openbmc#3029

Tested: Verified I see this error if the DownloadViaTFTP call
returns an error code.
Change-Id: I1547689059f45953b29aedda75c0599aec30079d
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js
index c20b2ca..f73a584 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -841,29 +841,19 @@
                 return deferred.promise;
               },
               downloadImage: function(host, filename){
-                var deferred = $q.defer();
-                $http({
+                return $http({
                   method: 'POST',
                   url: DataService.getHost() + "/xyz/openbmc_project/software/action/DownloadViaTFTP",
                   headers: {
-                      'Accept': 'application/json',
-                      'Content-Type': 'application/json'
+                    'Accept': 'application/json',
+                    'Content-Type': 'application/json'
                   },
                   withCredentials: true,
                   data: JSON.stringify({"data": [filename, host]}),
                   responseType: 'arraybuffer'
-                }).then(function(response, status, headers){
-                  deferred.resolve({
-                    data: response,
-                    status: status,
-                    headers: headers
-                  });
-                }, function(error){
-                  console.log(error);
-                  deferred.reject(error);
+                }).then(function(response){
+                  return response.data;
                 });
-
-                return deferred.promise;
               },
               getBMCEthernetInfo: function(){
                 var deferred = $q.defer();
diff --git a/app/configuration/controllers/firmware-controller.js b/app/configuration/controllers/firmware-controller.js
index 29d0412..618cad8 100644
--- a/app/configuration/controllers/firmware-controller.js
+++ b/app/configuration/controllers/firmware-controller.js
@@ -159,40 +159,22 @@
                     $scope.download = function(){
                         $scope.download_error_msg = "";
                         if(!$scope.download_host || !$scope.download_filename){
-                            $scope.download_error_msg = "Field is required!";
-                            return false;
+                          $scope.download_error_msg = "Field is required!";
+                          return false;
                         }
                         $scope.downloading = true;
                         APIUtils.downloadImage($scope.download_host, $scope.download_filename).then(function(response){
-                            var data = response.data;
-                            $scope.downloading = false;
-                            var headers = response.headers();
-
-                            var filename = headers['x-filename'];
-                            var contentType = headers['content-type'];
-
-                            if(!headers['x-filename']){
-                                filename = $scope.download_filename;
-                            }
-
-                            var linkElement = document.createElement('a');
-                            try {
-                                var blob = new Blob([data], { type: contentType });
-                                var url = window.URL.createObjectURL(blob);
-
-                                linkElement.setAttribute('href', url);
-                                linkElement.setAttribute("download", filename);
-
-                                var clickEvent = new MouseEvent("click", {
-                                    "view": window,
-                                    "bubbles": true,
-                                    "cancelable": false
-                                });
-                                linkElement.dispatchEvent(clickEvent);
-                            } catch (ex) {
-                                console.log(ex);
-                            }
-                        });
+                          $scope.downloading = false;
+                          // TODO: refresh firmware page to display new image
+                        }, function(error){
+                          $scope.downloading = false;
+                          $scope.displayError({
+                            modal_title: 'Error during downloading Image',
+                            title: 'Error during downloading Image',
+                            desc: JSON.stringify(error),
+                            type: 'Error'
+                          });
+                      });
                     }
 
                     $scope.changePriority = function(imageId, imageVersion, from, to){