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 9d2c4b0485
)
This commit is contained in:
parent
ef571a7532
commit
fe27a47817
@ -169,8 +169,9 @@
|
|||||||
onProgress(Math.round(event.loaded / event.total * 100));
|
onProgress(Math.round(event.loaded / event.total * 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
function onError() {
|
function onError(error) {
|
||||||
toastService.add('error', gettext('Unable to create the image.'));
|
toastService.add('error', gettext('Unable to create the image.'));
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiService[method]('/api/glance/images/', image)
|
return apiService[method]('/api/glance/images/', image)
|
||||||
|
@ -189,9 +189,15 @@
|
|||||||
|
|
||||||
service.createImage.apply(null, [{name: 1}]);
|
service.createImage.apply(null, [{name: 1}]);
|
||||||
|
|
||||||
expect(apiService.put).toHaveBeenCalledWith('/api/glance/images/', {name: 1});
|
try {
|
||||||
imageQueuedPromise.reject();
|
imageQueuedPromise.reject({'data': 'invalid'});
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
|
}catch (exp) {
|
||||||
|
expect(exp).toBeDefined();
|
||||||
|
expect(exp.data).toEqual('invalid');
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(apiService.put).toHaveBeenCalledWith('/api/glance/images/', {name: 1});
|
||||||
expect(toastService.add).toHaveBeenCalledWith('error', "Unable to create the image.");
|
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() {
|
it('second call is not started if the initial image creation fails', function() {
|
||||||
imageQueuedPromise.reject();
|
try {
|
||||||
|
imageQueuedPromise.reject({'data': 'invalid'});
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
|
}catch (exp) {
|
||||||
|
expect(exp).toBeDefined();
|
||||||
|
expect(exp.data).toEqual('invalid');
|
||||||
|
}
|
||||||
|
|
||||||
expect(apiService.put.calls.count()).toBe(1);
|
expect(apiService.put.calls.count()).toBe(1);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user