Mjh/fix issues with message (#24)

* Fix the ansible error

* Rolled version

* made the wrapping of the error more pythonic

* Fixed exception handling a little more

* Fixed exception handling a little more

* Fixed exception handling a little more

* Wrapping just the message?

* Moving over to a regular old exception

* Wrapping just the message

* Forget about wrapping the error

* Forget about wrapping the error

* Forget about wrapping the error

* Fixing error detections

* Fixed sanity test issues
This commit is contained in:
Mark Horninger 2024-03-10 22:42:34 -04:00 committed by GitHub
parent b5c798ea0e
commit 7bfce168a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 9 deletions

View File

@ -8,7 +8,7 @@ namespace: dominion_solutions
name: netbird
# The version of the collection. Must be compatible with semantic versioning
version: 0.1.5
version: 0.1.6
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md

View File

@ -93,7 +93,6 @@ from ansible.utils.display import Display
# Specific for the NetbirdAPI Class
import json
import re
try:
import requests
@ -151,8 +150,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
"""Get the inventory from the Netbird API"""
try:
self.peers = self.client.ListPeers()
except Exception as e:
raise AnsibleError(f"Could not retrieve the Netbird inventory: {e}")
except Exception:
raise AnsibleError("Could not retrieve the Netbird inventory. Check the API Key and URL.")
def _filter_by_config(self):
"""Filter peers by user specified configuration."""
@ -290,11 +289,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 response.status_code in [401, 404]:
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: