Handle empty response from API listNetworkOfferings and fix UI TypeError#9
Open
manikonda wants to merge 1 commit into
Open
Conversation
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').
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is to 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').
No UI/JS error when listNetworkOfferring API return empty results on Add Network page. Before this fix, it shows small error window with the "Request failed" message.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
How Has This Been Tested?
Select a project or default view for which there are no network offering are available then do below steps to test this.
Navigate to Network -> Guest Networks -> Add Network. Without this fix, it shows a small JS error window with "Request failed" message. This is because the response from the backend API is empty and causing undefined typeerror in the code. Now this is fixed with the code changes in this UI module.