From 1d532d20f52765923d30726db95c51a6cba8ae5f Mon Sep 17 00:00:00 2001 From: dettlaff Date: Tue, 24 Sep 2024 05:07:02 +0400 Subject: [PATCH] fix: read_account_uri error handling --- selfprivacy_api/services/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/selfprivacy_api/services/__init__.py b/selfprivacy_api/services/__init__.py index 4357e8e..317970e 100644 --- a/selfprivacy_api/services/__init__.py +++ b/selfprivacy_api/services/__init__.py @@ -40,12 +40,14 @@ def read_account_uri() -> str: try: with ACCOUNT_PATH.open("r") as file: account_info = json.load(file) - return account_info.get("registration", {}).get("uri", "URI not found") + return account_info["registration"]["uri"] except FileNotFoundError: print(f"Account file not found: {ACCOUNT_PATH}") except json.JSONDecodeError: - print(f"Can't get URI from JSON file: {ACCOUNT_PATH}") + print(f"Can not decode JSON file: {ACCOUNT_PATH}") + except KeyError: + print(f"URI not found in JSON file {ACCOUNT_PATH}") class ServiceManager(Service):