Skip to content

Handle empty response from API listNetworkOfferings and fix UI TypeError#9

Open
manikonda wants to merge 1 commit into
att:att/4.22.0.0from
manikonda:HandleEmptyResponseFromListNetworkOfferingsAPI
Open

Handle empty response from API listNetworkOfferings and fix UI TypeError#9
manikonda wants to merge 1 commit into
att:att/4.22.0.0from
manikonda:HandleEmptyResponseFromListNetworkOfferingsAPI

Conversation

@manikonda

Copy link
Copy Markdown

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

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

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.

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').

@cp1362 cp1362 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants