From 24836756039833005eb757174ff0a992713c172f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Madet?= Date: Thu, 21 Nov 2024 12:49:46 +0100 Subject: [PATCH] Added extra info to SendExceptionsToSlackMiddleware --- tapir/core/middleware.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tapir/core/middleware.py b/tapir/core/middleware.py index c82d3af0..a540a6b7 100644 --- a/tapir/core/middleware.py +++ b/tapir/core/middleware.py @@ -4,7 +4,6 @@ import requests from django.http import HttpRequest -from icecream import ic from tapir import settings @@ -20,22 +19,24 @@ def __call__(self, request: HttpRequest): response = self.get_response(request) except Exception as e: stacktrace_string = traceback.format_exc() - self.send_slack_message(e, stacktrace_string, request) + self.send_slack_message(e, stacktrace_string, request, source="Try/Catch") raise e return response def process_exception(self, request: HttpRequest, exception): stacktrace_string = traceback.format_exc() - self.send_slack_message(exception, stacktrace_string, request) + self.send_slack_message( + exception, stacktrace_string, request, source="Process exception" + ) return None @classmethod def send_slack_message( - cls, e: Exception, stacktrace_string: str, request: HttpRequest + cls, e: Exception, stacktrace_string: str, request: HttpRequest, source: str ): error_text = f"{e}" if not error_text: - error_text = "No exception raised" + error_text = "Could not get exception text" if not stacktrace_string: stacktrace_string = "No stacktrace available" @@ -45,6 +46,7 @@ def send_slack_message( "Hi @channel! The following error happened on the production server :ladybug:", is_markdown=True, ), + cls.build_section(f"Source: {source}"), cls.build_section(f"Request: {request}"), cls.build_section(f"User: {request.user}"), cls.build_section(f"Request headers: {request.headers}"),