Display error if error on upload
We were missing the rejected promise when image upload returned
an error. Now with this change and
https://gerrit.openbmc-project.xyz/#/c/9594/ image upload
now uploads an image and refreshes the page to display the image
or displays an error if the upload failed.
Resolves openbmc/openbmc#2960
Tested: See an error if a bad image. GUI refreshes if the image
was uploaded successfully.
Change-Id: I5f4030fb29fc08aa65dd0d36e32368106c31a76b
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 431c7ce..e74b196 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -818,8 +818,7 @@
return deferred.promise;
},
uploadImage: function(file){
- var deferred = $q.defer();
- $http({
+ return $http({
method: 'POST',
timeout: 5 * 60 * 1000,
url: DataService.getHost() + "/upload/image",
@@ -829,15 +828,8 @@
withCredentials: true,
data: file
}).then(function(response){
- var json = JSON.stringify(response.data);
- var content = JSON.parse(json);
- deferred.resolve(content);
- }, function(error){
- console.log(error);
- deferred.reject(error);
+ return response.data;
});
-
- return deferred.promise;
},
downloadImage: function(host, filename){
return $http({
diff --git a/app/configuration/controllers/firmware-controller.js b/app/configuration/controllers/firmware-controller.js
index 50cff28..d209a5a 100644
--- a/app/configuration/controllers/firmware-controller.js
+++ b/app/configuration/controllers/firmware-controller.js
@@ -148,22 +148,21 @@
}
$scope.upload = function(){
- if($scope.file) {
- $scope.uploading = true;
- APIUtils.uploadImage($scope.file).then(function(response){
- $scope.uploading = false;
- if(response.status == 'error'){
- $scope.displayError({
- modal_title: response.data.description,
- title: response.data.description,
- desc: response.data.exception,
- type: 'Error'
- });
- }else{
- $scope.loadFirmwares();
- }
- });
- }
+ if($scope.file) {
+ $scope.uploading = true;
+ APIUtils.uploadImage($scope.file).then(function(response){
+ $scope.uploading = false;
+ $scope.loadFirmwares();
+ }, function(error){
+ $scope.uploading = false;
+ $scope.displayError({
+ modal_title: 'Error during image upload',
+ title: 'Error during image upload',
+ desc: 'Error uploading image',
+ type: 'Error uploading image, please check the image'
+ });
+ });
+ }
}
$scope.download = function(){