diff --git a/data_safe_haven/external/api/azure_cli.py b/data_safe_haven/external/api/azure_cli.py index 7ff6b09de7..8483c2ddef 100644 --- a/data_safe_haven/external/api/azure_cli.py +++ b/data_safe_haven/external/api/azure_cli.py @@ -42,23 +42,22 @@ def account(self) -> AzureCliAccount: stderr=subprocess.PIPE, encoding="utf8", ) - - try: - result_dict = json.loads(result) - except json.JSONDecodeError as exc: - msg = f"Unable to parse Azure CLI output as JSON.\n{result}" - raise DataSafeHavenAzureError(msg) from exc - - self._account = AzureCliAccount( - name=result_dict.get("user").get("name"), - id_=result_dict.get("id"), - tenant_id=result_dict.get("tenantId"), - ) - except subprocess.CalledProcessError as exc: msg = f"Error getting account information from Azure CLI.\n{exc.stderr}" raise DataSafeHavenAzureError(msg) from exc + try: + result_dict = json.loads(result) + except json.JSONDecodeError as exc: + msg = f"Unable to parse Azure CLI output as JSON.\n{result}" + raise DataSafeHavenAzureError(msg) from exc + + self._account = AzureCliAccount( + name=result_dict.get("user").get("name"), + id_=result_dict.get("id"), + tenant_id=result_dict.get("tenantId"), + ) + return self._account def confirm(self) -> None: