Skip to content

Commit

Permalink
Add logger to log exceptions in AJAX middleware
Browse files Browse the repository at this point in the history
This commit will introduce a logger which writes errors
into the log file and thus fix the issue 1353.
  • Loading branch information
Sebastian Lange authored and sevein committed Apr 6, 2021
1 parent 612d07a commit 893bc82
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/dashboard/src/middleware/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import sys
import traceback
import logging

from django.conf import settings
from django.http import HttpResponseServerError
Expand All @@ -30,15 +31,25 @@
import elasticsearch


logger = logging.getLogger("archivematica.dashboard")


class AJAXSimpleExceptionResponseMiddleware(MiddlewareMixin):
def process_exception(self, request, exception):
if not settings.DEBUG or not request.is_ajax():
return
(exc_type, exc_info, tb) = sys.exc_info()
tracebacks = traceback.format_tb(tb)
logger.error(
"Processing exception %s at %s. Traceback %s",
exception,
request.path,
tracebacks,
)
response = "%s\n" % exc_type.__name__
response += "%s\n\n" % exc_info
response += "TRACEBACK:\n"
for tb in traceback.format_tb(tb):
for tb in tracebacks:
response += "%s\n" % tb
return HttpResponseServerError(response)

Expand Down

0 comments on commit 893bc82

Please sign in to comment.