From 784335683268fcb09b533585a4bb9700bc2fa1be Mon Sep 17 00:00:00 2001 From: Noah Canadea Date: Mon, 4 Dec 2023 08:07:52 +0000 Subject: [PATCH] fix(registry_handler): Handle api exceptions --- infrapatch/core/utils/terraform/registry_handler.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/infrapatch/core/utils/terraform/registry_handler.py b/infrapatch/core/utils/terraform/registry_handler.py index a2ad26c..2b1dcb6 100644 --- a/infrapatch/core/utils/terraform/registry_handler.py +++ b/infrapatch/core/utils/terraform/registry_handler.py @@ -140,8 +140,10 @@ def _send_request(self, url: str, registry_base_domain: str): request_object.add_header("Authorization", f"Bearer {token}") else: log.debug(f"No credentials found for registry '{registry_base_domain}', using unauthenticated request.") - - response = request.urlopen(request_object) + try: + response = request.urlopen(request_object) + except Exception as e: + raise TerraformRegistryException(f"Registry request returned an error '{url}': {e}") if response.status == 404: raise TerraformRegistryException(f"Registry resource '{url}' not found.") elif response.status >= 400: