INNER CODE UNIT · Python
fallback_exception_middleware
akutayural/APIException · api_exception/__init__.py:532
async def fallback_exception_middleware(request: Request, call_next: Callable):
try:
return await call_next(request)
except Exception as e:
tb = "".join(traceback.format_exception(type(e), e, e.__traceback__))
if log:
meta: Dict[str, Any] = {
"event": "unhandled_exception",
"path": request.url.path,
"method": request.method,
"client_ip": request.client.host if request.client else "unknown",
"http_version": request.scope.get("http_version", None),
"exception_type": type(e).__name__,
"exception_args": e.args,
}
if log_request_context:
meta.update(_collect_headers(request, log_header_keys))