1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

refactor: allow raising resource not found from any module

This commit is contained in:
jo 2025-12-03 14:42:09 +01:00
parent e3e3f8dd2d
commit b480585c35
No known key found for this signature in database
GPG key ID: B2FEC9B22722B984

View file

@ -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