mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-03 23:51:48 +00:00
refactor: allow raising resource not found from any module (#761)
##### SUMMARY Allows to raise a not found error from any module.
This commit is contained in:
parent
e3e3f8dd2d
commit
095fa8a2e0
1 changed files with 4 additions and 4 deletions
|
|
@ -33,8 +33,8 @@ def client_check_required_lib():
|
|||
raise ClientException(missing_required_lib("python-dateutil"))
|
||||
|
||||
|
||||
def _client_resource_not_found(resource: str, param: str | int):
|
||||
return ClientException(f"resource ({resource.rstrip('s')}) does not exist: {param}")
|
||||
def client_resource_not_found(resource: str, param: str | int):
|
||||
return ClientException(f"resource ({resource}) does not exist: {param}")
|
||||
|
||||
|
||||
def client_get_by_name_or_id(client: Client, resource: str, param: str | int):
|
||||
|
|
@ -55,13 +55,13 @@ def client_get_by_name_or_id(client: Client, resource: str, param: str | int):
|
|||
try:
|
||||
int(param)
|
||||
except ValueError as exception:
|
||||
raise _client_resource_not_found(resource, param) from exception
|
||||
raise client_resource_not_found(resource.rstrip("s"), param) from exception
|
||||
|
||||
try:
|
||||
return resource_client.get_by_id(param)
|
||||
except APIException as exception:
|
||||
if exception.code == "not_found":
|
||||
raise _client_resource_not_found(resource, param) from exception
|
||||
raise client_resource_not_found(resource.rstrip("s"), param) from exception
|
||||
raise exception
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue