Open fraser-langton opened 2 weeks ago
I have the same issue
@daniilmastrangeli a fix I have found for now is to add_exception_handler which catches the exception and if re-raised will display the trace to stdout as expected
import uvicorn
from fastapi import FastAPI, Request
from starlette.middleware.base import BaseHTTPMiddleware
app = FastAPI()
class MyExc(Exception):
...
@app.get("/info")
def info():
raise MyExc
private_api = FastAPI()
@private_api.get("/info")
def info():
raise MyExc
app.mount("/private", private_api)
class Middleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
return await call_next(request)
def re_raise_exception(_: Request, exc: Exception):
raise exc from exc
app.add_middleware(Middleware)
app.add_exception_handler(Exception, re_raise_exception) # raises the exception in the handler which results in getting handled by a different context
if __name__ == "__main__":
uvicorn.run(app, port=8000)
Regression of #1976 #1977 #1609 #1940
This time I have noticed that changing
MyExc(Exception)
toMyExc(BaseException)
means the error does get sent to stdout (if that helps) I tried to have a dig but I am not too sure where that catch exception is that is catching the Exception (and silently passing) and not the BaseExceptionstarlette==0.37.2 fastapi==0.111.0