HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
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)