From 48ca6ec3ea93c4b452e7100f75fe26e300024b36 Mon Sep 17 00:00:00 2001 From: Ayo Ayco Date: Sun, 19 Jan 2025 14:51:10 +0100 Subject: [PATCH] feat: improve error handling of mastodon operations - don't raise exception when reading secret file fails - raise exception when initializing masto client w/ persisted secret fails --- mastodon.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mastodon.py b/mastodon.py index e82e465..e0da037 100644 --- a/mastodon.py +++ b/mastodon.py @@ -30,7 +30,7 @@ def initialize_client(app): secret = secret_file.read() except OSError as e: message = '>>> No secret found.' - raise Exception(message) + print(message) # todo, check if access_token exist in secret_file if secret == None: @@ -49,8 +49,12 @@ def initialize_client(app): else: #... otherwise, reuse - mastodon = Mastodon(access_token=app['secret_file']) - print('>>> Reused persisted token!') + try: + mastodon = Mastodon(access_token=app['secret_file']) + print('>>> Reused persisted token!') + except: + message = '>>> Persisted token did not work' + raise Exception(message) if session_id == None: try: