Infoblox-PS / ibx-sdk

Basic Tools and Functions used by other Integrations.
Apache License 2.0
4 stars 0 forks source link

exceptions were not bubbling properly #77

Closed yeti9990 closed 9 months ago

yeti9990 commented 9 months ago

Ensure exceptions are properly bubbled. A user should NOT have to write nested exception code like so:

def get_all_zones(view: str) -> list:
    try:
        res = wapi.get('zone_auth', {'view': view})
    except WapiRequestException as err:
        log.error(err)
        sys.exit(1)
    else:
        if res.status_code != 200:
            log.error(res.text)
            sys.exit(1)
    return res.json()

Our code is passing things along, and it needs to do a better job of checking requests.exceptions vs WAPI exceptions so we can code as follows:

def get_all_zones(view: str) -> list:
    try:
        res = wapi.get('zone_auth', {'view': view})
    except WapiRequestException as err:
        log.error(err)
        sys.exit(1)
     return res.json()