Skip to content

Commit

Permalink
Merge pull request #748 from thecourseforum/dev
Browse files Browse the repository at this point in the history
Error Logging
  • Loading branch information
ajnye authored Nov 10, 2023
2 parents bc36e91 + 1e76571 commit d6a1ef9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tcf_core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'tcf_core.settings.record_middleware.RecordMiddleware'
'tcf_core.settings.handle_exceptions_middleware.HandleExceptionsMiddleware',
'tcf_core.settings.record_middleware.RecordMiddleware',
]

ROOT_URLCONF = 'tcf_core.urls'
Expand Down
21 changes: 21 additions & 0 deletions tcf_core/settings/handle_exceptions_middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Middleware for recording errors to print out."""
import sys
import traceback


class HandleExceptionsMiddleware:
"""Records information about errors at any point."""
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
response = self.get_response(request)

return response

def process_exception(self, request, exception):
"""Gets and prints out all errors to terminal for tracking"""
print('Error on Load')
print("Internal Server Error: " + request.get_full_path(), file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
print(exception)

0 comments on commit d6a1ef9

Please sign in to comment.