File: //home/arjun/projects/buyercall_forms/buyercall/buyercall/lib/catch_exception_middleware.py
from flask import request
class InternalServerErrorMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
try:
return self.app(environ, start_response)
except Exception as e:
print(f"The exception caught in the middleware: {e}")
summary = e.args[0] if e.args else "An error occurred"
# save error summary to request log
#from buyercall.blueprints.sysadmin.models import RequestLog
#request_id = request.environ.get('HTTP_X_REQUEST_ID')
#RequestLog().update_record(
# request_id, {"error": summary, "response_code": 500})
# return self.app(environ, start_response)