@@ -117,15 +117,41 @@ def updatePos(ts3conn):
117
117
onlineController [position ['identifier' ]] = []
118
118
119
119
# Get the user info for the controller from the ZNY website
120
- userInfo = requests .get (
121
- zny_web_instance + '/api/teamspeak/userIdentity?cid={}' .format (position ['cid' ])).json ()
120
+ try :
121
+ user_info_response = requests .get (
122
+ zny_web_instance + '/api/teamspeak/userIdentity?cid={}' .format (position ['cid' ]))
123
+ user_info_response .raise_for_status ()
124
+ if not user_info_response .content :
125
+ raise ValueError ("Empty response received from user info API." )
126
+ userInfo = user_info_response .json ()
127
+ except requests .RequestException as e :
128
+ logger .error (f"Request failed: { e } " )
129
+ raise
130
+ except ValueError as e :
131
+ logger .error (f"Invalid response: { e } " )
132
+ raise
133
+ except json .JSONDecodeError as e :
134
+ logger .error (f"Failed to parse JSON response: { e } " )
135
+ logger .error (f"Response content: { user_info_response .text } " )
136
+ raise
137
+
122
138
123
139
# Add the user to the position in the dictionary for that position
124
140
for uid in userInfo :
125
141
onlineController [position ['identifier' ]].append (uid )
126
142
127
143
# Connect to the database
128
- conn = engine .connect ()
144
+ try :
145
+ conn = engine .connect ()
146
+ except Exception as e :
147
+ # Log the error with as much detail as possible
148
+ logger .error (f"Database connection failed: { e } " )
149
+ # It might be beneficial to include the database URL, masking sensitive info
150
+ sanitized_db_url = re .sub (r'//(.*):(.*)@' , '//***:***@' , str (db ))
151
+ logger .error (f"Failed to connect to database at { sanitized_db_url } " )
152
+ # After logging, you might want to raise an exception to halt the execution
153
+ # or handle the error in a way that makes sense for your application
154
+ raise
129
155
130
156
# Get the list of all positions from the database
131
157
positionsAll = conn .execute (select ([table ])).fetchall ()
0 commit comments