From 33c27c1cbaa36c056b062727beee13ae1e8f1192 Mon Sep 17 00:00:00 2001 From: Jake Charman Date: Fri, 18 Jul 2025 14:38:14 +0100 Subject: [PATCH] Improved logging --- src/contact.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/contact.py b/src/contact.py index 27957bc..f725883 100755 --- a/src/contact.py +++ b/src/contact.py @@ -16,7 +16,8 @@ def validate_turnstile(response: str, ip: str) -> bool: 'response': response, 'remoteip': ip, 'idempotency_key': uuid4() - } + }, + timeout=30 ).json() return cf_response.get('success', False) @@ -24,7 +25,8 @@ def validate_turnstile(response: str, ip: str) -> bool: def send_to_discord(form: dict) -> bool: try: discord_hook = environ['DISCORD_WEBHOOK'] - except: + except KeyError as e: + app.logger.error(e.with_traceback()) return False discord_msg = dedent( f''' @@ -42,11 +44,12 @@ def send_to_discord(form: dict) -> bool: data={ 'username': form.get('name'), 'content': discord_msg - } - ).status_code - - if discord_response == 204: + }, + timeout=30 + ) + if discord_response.status_code == 204: return True + app.logger.error(discord_response.status_code, discord_response.text) return False @app.route('/contact/', methods=('GET', 'POST'))