summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-02-05 05:02:55 +0000
committerGerrit Code Review <review@openstack.org>2018-02-05 05:02:55 +0000
commit695910902fb1d8a2ba16404861bcd2e94edebd72 (patch)
tree5d157277fb02978f0a5ed2b2d26ef8d9ec350d5a
parent26d36168ce44e7f3b9e99b2c2b731942cb5188db (diff)
parentf66f87049dc1c5445c7953a30367574997c8949a (diff)
downloadhorizon-695910902fb1d8a2ba16404861bcd2e94edebd72.tar.gz
Merge "Fix the error format of glance's createImage" into stable/pike
-rw-r--r--openstack_dashboard/static/app/core/openstack-service-api/glance.service.js7
-rw-r--r--openstack_dashboard/static/app/core/openstack-service-api/glance.service.spec.js29
2 files changed, 25 insertions, 11 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 7c0da41a5..7179aa418 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
@@ -170,8 +170,11 @@
}
function onError(error) {
- toastService.add('error', gettext('Unable to create the image.'));
- throw error;
+ if (error && error.data) {
+ throw error;
+ } else {
+ throw gettext('Unable to create the image.');
+ }
}
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 a1eed6612..5bb5fb726 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
@@ -185,20 +185,31 @@
}));
it('shows error message when arguments are insufficient', function() {
- spyOn(toastService, 'add');
-
service.createImage.apply(null, [{name: 1}]);
try {
imageQueuedPromise.reject({'data': 'invalid'});
$rootScope.$apply();
- }catch (exp) {
- expect(exp).toBeDefined();
- expect(exp.data).toEqual('invalid');
+ } catch (error) {
+ expect(error).toBeDefined();
+ expect(error.data).toEqual('invalid');
+ }
+
+ expect(apiService.put).toHaveBeenCalledWith('/api/glance/images/', {name: 1});
+ });
+
+ it('shows a generic message when it gets a unexpected error', function() {
+ service.createImage.apply(null, [{name: 1}]);
+
+ try {
+ imageQueuedPromise.reject();
+ $rootScope.$apply();
+ } catch (error) {
+ expect(error).toBeDefined();
+ expect(error).toEqual('Unable to create the image.');
}
expect(apiService.put).toHaveBeenCalledWith('/api/glance/images/', {name: 1});
- expect(toastService.add).toHaveBeenCalledWith('error', "Unable to create the image.");
});
describe('external upload of a local file', function() {
@@ -237,9 +248,9 @@
try {
imageQueuedPromise.reject({'data': 'invalid'});
$rootScope.$apply();
- }catch (exp) {
- expect(exp).toBeDefined();
- expect(exp.data).toEqual('invalid');
+ } catch (error) {
+ expect(error).toBeDefined();
+ expect(error.data).toEqual('invalid');
}
expect(apiService.put.calls.count()).toBe(1);