From 87549bd54b395a904ad6d64756d7d7e11f53cdd1 Mon Sep 17 00:00:00 2001 From: "Mark J. Horninger" Date: Sun, 10 Mar 2024 22:31:40 -0400 Subject: [PATCH] Moving over to a regular old exception --- plugins/inventory/netbird.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/inventory/netbird.py b/plugins/inventory/netbird.py index c3c827d..664c7e9 100644 --- a/plugins/inventory/netbird.py +++ b/plugins/inventory/netbird.py @@ -152,7 +152,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): try: self.peers = self.client.ListPeers() except Exception as e: - raise AnsibleError(f"Could not retrieve the Netbird inventory: {e.message}") + raise AnsibleError from e def _filter_by_config(self): """Filter peers by user specified configuration.""" @@ -290,11 +290,8 @@ class NetbirdApi: } peers = [] response = requests.request("GET", url, headers=headers) - if response.status_code in [401]: - raise ConnectionRefusedError(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.") - - elif re.match('4\\d\\d', response.status_code): - raise ConnectionError(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.") + if re.match('4\\d\\d', response.status_code): + raise Exception(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.") peer_json = json.loads(response.text) for current_peer_map in peer_json: