Prevent BaseHTTPMiddleware from hiding errors of StreamingResponse#1459
Prevent BaseHTTPMiddleware from hiding errors of StreamingResponse#1459Kludex merged 5 commits intoKludex:masterfrom o-fedorov:feature/o-fedorov/base-middleware-do-not-hide-stream-errors
Conversation
Kludex
left a comment
There was a problem hiding this comment.
Alternative to #1452
Would you mind adding this test?
def test_exception_on_mounted_apps(test_client_factory):
sub_app = Starlette(routes=[Route("/", exc)])
app.mount("/sub", sub_app)
client = test_client_factory(app)
with pytest.raises(Exception) as ctx:
client.get("/sub/")
assert str(ctx.value) == "Exc"* remove `nonlocal app_exc`; * add extra test.
The test is added |
|
I don't think this work if the from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import Response
class CustomHeaderMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
await call_next(request)
return Response("Do you see an exception now?")
middleware = [
Middleware(CustomHeaderMiddleware)
]
app = Starlette(routes=routes, middleware=middleware)Can you confirm? Using the same #1452 should be able to solve this. |
|
Sorry, both this approach and #1452 seems to not solving the issue if the Response object from the middleware is ignored |
Kludex
left a comment
There was a problem hiding this comment.
Sorry, both this approach and #1452 seems to not solving the issue if the Response object from the middleware is ignored
My bad... That exception is not even raised! 😆
In any case, I like this PR more than the one I created because it brings the exception conditional closer to where it can be retrieved.
…ide-stream-errors
|
Thanks for the PR @o-fedorov ! :) |
The issue is observed when:
Prior to v0.17.0 the exception was raised and the traceback was printed to the server logs. Now it is silently ignored.
Edit by @Kludex : Closes #1433