ソースを参照

Added some additional error handling and logging

deadtom 1 ヶ月 前
コミット
f3d6a516bb
1 ファイル変更15 行追加9 行削除
  1. 15 9
      ownchatbot/reward_handlers.py

+ 15 - 9
ownchatbot/reward_handlers.py

@@ -263,10 +263,13 @@ def fulfill_reward(db, reward_id):  # Mark a reward as fulfilled in the database
 def all_active_votes(db):  # Get only active votes
     votes = all_votes(db)
     all_active_votes = []
-    for name, count, info in votes:
-        if is_reward_active(name):
-            all_active_votes.append((name, count, info))
-    return all_active_votes
+    try:
+        for name, count, info in votes:
+            if is_reward_active(name):
+                all_active_votes.append((name, count, info))
+        return all_active_votes
+    except Exception as aaverror:
+        current_app.logger.error(f'General exception: {aaverror}')
 
 
 def all_goals(db):  # Get all the goals
@@ -275,17 +278,20 @@ def all_goals(db):  # Get all the goals
             "SELECT name, progress, target, info FROM goals"
         )
         return cursor.fetchall()
-    except Error as agerror:
+    except Exception as agerror:
         current_app.logger.error(f'Couldn\'t select all goals: {agerror.args[0]}')
 
 
 def all_active_goals(db):  # Get only active goals
     goals = all_goals(db)
     all_active_goals = []
-    for name, progress, target, info in goals:
-        if is_reward_active(name):
-            all_active_goals.append((name, progress, target, info))
-    return all_active_goals
+    try:
+        for name, progress, target, info in goals:
+            if is_reward_active(name):
+                all_active_goals.append((name, progress, target, info))
+        return all_active_goals
+    except Exception as aagerror:
+        current_app.logger.error(f'General exception: {aagerror}')
 
 
 def all_active_rewards():  # Get only active rewards