summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgugl <gloria.fang.gu@suse.com>2017-04-18 19:17:42 -0700
committerKevin Carter (cloudnull) <kevin@cloudnull.com>2017-06-15 00:26:29 +0000
commitfe27a478174c87cfa250bdc49851d9fc0972282d (patch)
treeeff4200eb238c22da3802566112f873d36517701
parentef571a753234207e50bf2bc3ab57770dc843f285 (diff)
downloadhorizon-fe27a478174c87cfa250bdc49851d9fc0972282d.tar.gz
Reject result when createImage call has error
When there is an error from createImage, it still invokes onCreateImage function which should be invoked only when successful service call. Fixed onError function to throw the error and the error will show up in the modal toast message. Change-Id: I20725f894835714d8245ec8b192937110cf11ab5 Closes-bug: #1630833 (cherry picked from commit 9d2c4b0485cdf1826f0f1ec80094c80aa244665e)
-rw-r--r--openstack_dashboard/static/app/core/openstack-service-api/glance.service.js3
-rw-r--r--openstack_dashboard/static/app/core/openstack-service-api/glance.service.spec.js19
2 files changed, 17 insertions, 5 deletions
diff --git a/openstack_dashboard/static/app/core/openstack-service-api/glance.service.js b/openstack_dashboard/static/app/core/openstack-service-api/glance.service.js
index 99b6b2146..7c0da41a5 100644
--- a/openstack_dashboard/static/app/core/openstack-service-api/glance.service.js
+++ b/openstack_dashboard/static/app/core/openstack-service-api/glance.service.js
@@ -169,8 +169,9 @@
onProgress(Math.round(event.loaded / event.total * 100));
}
- function onError() {
+ function onError(error) {
toastService.add('error', gettext('Unable to create the image.'));
+ throw error;
}
return apiService[method]('/api/glance/images/', image)
diff --git a/openstack_dashboard/static/app/core/openstack-service-api/glance.service.spec.js b/openstack_dashboard/static/app/core/openstack-service-api/glance.service.spec.js
index 7d4a4f17e..3e9675680 100644
--- a/openstack_dashboard/static/app/core/openstack-service-api/glance.service.spec.js
+++ b/openstack_dashboard/static/app/core/openstack-service-api/glance.service.spec.js
@@ -189,9 +189,15 @@
service.createImage.apply(null, [{name: 1}]);
+ try {
+ imageQueuedPromise.reject({'data': 'invalid'});
+ $rootScope.$apply();
+ }catch (exp) {
+ expect(exp).toBeDefined();
+ expect(exp.data).toEqual('invalid');
+ }
+
expect(apiService.put).toHaveBeenCalledWith('/api/glance/images/', {name: 1});
- imageQueuedPromise.reject();
- $rootScope.$apply();
expect(toastService.add).toHaveBeenCalledWith('error', "Unable to create the image.");
});
@@ -228,8 +234,13 @@
});
it('second call is not started if the initial image creation fails', function() {
- imageQueuedPromise.reject();
- $rootScope.$apply();
+ try {
+ imageQueuedPromise.reject({'data': 'invalid'});
+ $rootScope.$apply();
+ }catch (exp) {
+ expect(exp).toBeDefined();
+ expect(exp.data).toEqual('invalid');
+ }
expect(apiService.put.calls.count()).toBe(1);
});