From c72e1b00fe29c54feba7c5764772d83a80b81731 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Mon, 24 Mar 2025 13:45:33 +0100 Subject: [PATCH] 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 --- .../core/openstack-service-api/network.service.js | 15 ++++++++++----- .../openstack-service-api/network.service.spec.js | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/openstack_dashboard/static/app/core/openstack-service-api/network.service.js b/openstack_dashboard/static/app/core/openstack-service-api/network.service.js index c84dff1f60..e5b8e78dc5 100644 --- a/openstack_dashboard/static/app/core/openstack-service-api/network.service.js +++ b/openstack_dashboard/static/app/core/openstack-service-api/network.service.js @@ -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; }); } diff --git a/openstack_dashboard/static/app/core/openstack-service-api/network.service.spec.js b/openstack_dashboard/static/app/core/openstack-service-api/network.service.spec.js index 913795121a..e16a577d4b 100644 --- a/openstack_dashboard/static/app/core/openstack-service-api/network.service.spec.js +++ b/openstack_dashboard/static/app/core/openstack-service-api/network.service.spec.js @@ -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 } ];