-
-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent BaseHTTPMiddleware from hiding errors of StreamingResponse #1459
Prevent BaseHTTPMiddleware from hiding errors of StreamingResponse #1459
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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