Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Nnonexistent
Copy link
Contributor

Bug description:

If httpx client uses asgi transport with raise_app_exceptions=False and response is not complete, exception is still raised.

This is mostly come up in tests where you want to check how your application behave in error states. But currently it works only with non-streaming responses, which is quite limiting.

I propose simple fix for such non-complete responses to be able to comply with the raise_app_exceptions=False.

Test case included.

async with httpx.AsyncClient(app=raise_exc, transport=transport) as client:
response = await client.get("http://www.example.org/")

assert response.status_code == 500
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behaviour of this test before the code change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test failed with RuntimeError being raised from raise_exc

Copy link
Contributor

@lovelydinosaur lovelydinosaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, yup.

@lovelydinosaur
Copy link
Contributor

Okay, let's also add this to the CHANGELOG.
What's the best user-facing description we can add here?

Return 500 error response instead of exceptions when raise_app_exceptions=False is set on ASGITransport.

Perhaps?

@lovelydinosaur lovelydinosaur merged commit a682f6f into encode:master May 21, 2023
@trim21 trim21 mentioned this pull request Aug 1, 2023
samclearman pushed a commit to titanmsp/httpx that referenced this pull request Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants