Fix the error format of glance's createImage

Uppon failure, the createImage function returned a raw xhr error
that was incompatible with the wizard modal, making it display
the [Object object] error.

This change makes it so a generic error message is thrown directly
if it's not an handled glance error, so it could be shown on top of
the wizard modal.

Change-Id: I637bf1002630fe21f5ad20a7a047ec65ebc052dc
Closes-bug: #1703708
This commit is contained in:
Pascal Boutin 2017-07-26 17:15:29 -04:00
parent e5339c35d0
commit 09a2afef35
2 changed files with 25 additions and 11 deletions

View File

@ -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)

View File

@ -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);