In order to log "some dependency, somewhere deep" errors that trigger a server error 500, without stack traces in the console log on production instances due to DEBUG=False
, I implemented the standard custom 500 handler that a fair number of Stackoverflow questions about printing a stack trace for a 500 error recommend:
import sys
import traceback
def server_error_500_handler(request):
type, value, tb = sys.exc_info()
print('\n----intercepted 500 error stack trace----')
print(value)
print(type)
print(traceback.format_exception(type, value, tb))
print('----\n')
However, these then also all say to end with render(request, '500.html')
, whereas I don't want to serve a custom 500 page, but want the code to go "back" (if there is such a thing) to just serving whatever Django itself does already. Is there some way to make it do that? Or, is there some way to listen for the 500 event without hijacking the 500 error return codepath?