Catch callback in network service doesn't throw

This is the same issue as described in [1].

Example: When octavia-dashboard uses the network service
to associate a floating IP and the call fails the then()
callback saying it was successful will be called in
octavia-dashboard alongside the error toast that is
shown in the catch() callback.

We should throw in the error callback so that the
then() callback is not called.

[1] https://review.opendev.org/c/openstack/horizon/+/922094

Change-Id: Ieb4b0b76b59fca2e750c576725b0a8987b0837a1
Signed-off-by: Tobias Urdin <tobias.urdin@binero.com>
This commit is contained in:
Tobias Urdin
2025-03-24 13:45:33 +01:00
parent 2792db67a7
commit c72e1b00fe
2 changed files with 20 additions and 10 deletions

View File

@@ -59,8 +59,9 @@
*/
function getFloatingIps() {
return apiService.get('/api/network/floatingips/')
.catch(function onError() {
.catch(function onError(response) {
toastService.add('error', gettext('Unable to retrieve floating IPs.'));
throw response;
});
}
@@ -74,8 +75,9 @@
*/
function getFloatingIpPools() {
return apiService.get('/api/network/floatingippools/')
.catch(function onError() {
.catch(function onError(response) {
toastService.add('error', gettext('Unable to retrieve floating IP pools.'));
throw response;
});
}
@@ -91,8 +93,9 @@
*/
function allocateFloatingIp(poolId) {
return apiService.post('/api/network/floatingip/', { pool_id: poolId })
.catch(function onError() {
.catch(function onError(response) {
toastService.add('error', gettext('Unable to allocate new floating IP address.'));
throw response;
});
}
@@ -111,8 +114,9 @@
function associateFloatingIp(addressId, portId) {
var params = { address_id: addressId, port_id: portId };
return apiService.patch('/api/network/floatingip/', params)
.catch(function onError() {
.catch(function onError(response) {
toastService.add('error', gettext('Unable to associate floating IP address.'));
throw response;
});
}
@@ -127,8 +131,9 @@
*/
function disassociateFloatingIp(addressId) {
return apiService.patch('/api/network/floatingip/', { address_id: addressId })
.catch(function onError() {
.catch(function onError(response) {
toastService.add('error', gettext('Unable to disassociate floating IP address.'));
throw response;
});
}

View File

@@ -42,13 +42,15 @@
func: 'getFloatingIps',
method: 'get',
path: '/api/network/floatingips/',
error: 'Unable to retrieve floating IPs.'
error: 'Unable to retrieve floating IPs.',
throws: true
},
{
func: 'getFloatingIpPools',
method: 'get',
path: '/api/network/floatingippools/',
error: 'Unable to retrieve floating IP pools.'
error: 'Unable to retrieve floating IP pools.',
throws: true
},
{
func: 'allocateFloatingIp',
@@ -56,7 +58,8 @@
path: '/api/network/floatingip/',
data: { pool_id: 'pool' },
error: 'Unable to allocate new floating IP address.',
testInput: [ 'pool' ]
testInput: [ 'pool' ],
throws: true
},
{
func: 'associateFloatingIp',
@@ -64,7 +67,8 @@
path: '/api/network/floatingip/',
data: { address_id: 'address', port_id: 'port' },
error: 'Unable to associate floating IP address.',
testInput: [ 'address', 'port' ]
testInput: [ 'address', 'port' ],
throws: true
},
{
func: 'disassociateFloatingIp',
@@ -72,7 +76,8 @@
path: '/api/network/floatingip/',
data: { address_id: 'address' },
error: 'Unable to disassociate floating IP address.',
testInput: [ 'address' ]
testInput: [ 'address' ],
throws: true
}
];