Skip to content

Commit

Permalink
Added extra info to SendExceptionsToSlackMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Theophile-Madet committed Nov 21, 2024
1 parent c7e1524 commit 2483675
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tapir/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import requests
from django.http import HttpRequest
from icecream import ic

from tapir import settings

Expand All @@ -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"
Expand All @@ -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}"),
Expand Down

0 comments on commit 2483675

Please sign in to comment.