Skip to content

Commit 13af31e

Browse files
authored
Handle empty response from API listNetworkOfferings (#9)
Fix unhandled error when the response from API listNetworkOfferings is empty and causing TypeError on JS code. This is to prevent a crash and showing pop up error window — If the API returns a response where listnetworkofferingsresponse has no networkoffering key (which happens when there are zero results — CloudStack omits empty arrays in JSON responses), the value would be undefined. The next line calls .filter() on it, which would throw TypeError: Cannot read properties of undefined (reading 'filter').
1 parent 830d976 commit 13af31e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

ui/src/views/network/CreateIsolatedNetworkForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ export default {
551551
this.networkOfferings = []
552552
this.selectedNetworkOffering = {}
553553
getAPI('listNetworkOfferings', params).then(json => {
554-
this.networkOfferings = json.listnetworkofferingsresponse.networkoffering
554+
this.networkOfferings = json.listnetworkofferingsresponse.networkoffering || []
555555
this.networkOfferings = this.networkOfferings.filter(offering => offering.fornsx === this.selectedZone.isnsxenabled)
556556
if (!this.selectedZone.routedmodeenabled) {
557557
this.networkOfferings = this.networkOfferings.filter(offering => offering.networkmode !== 'ROUTED')

0 commit comments

Comments
 (0)