Support raise_for_status
on request methods and clients
#2336
Replies: 3 comments 6 replies
-
If
Which would probably be nicer than another keyword argument and not change the call interface. |
Beta Was this translation helpful? Give feedback.
-
Hi! Any plans to implement this? Because I also dislike the redundant code. I had to make this change for all my requests. data = httpx.get(...).json() to response = httpx.get(...)
response.raise_for_status()
data = response.json() This becomes even more redundant when having multiple requests in one file! Allow me to mention that I'd prefer a new param for this, that's what I'm used to from other libs. Since it could have a default, it would be backwards compatible anyways. # A
httpx.get(..., { ..., raise_for_status: True}).json()
# B
```python
https.get(...).raise_for_status().json() I also would like to discuss if HTTPX should actually raise an exception for status codes >= 400 by default, any thoughts? |
Beta Was this translation helpful? Give feedback.
-
I would like to see this functionality as well. I would like to consolidate my exception handling and formatting of a useful helpful message to a single module for a CLI application I'm building. I'd like this exception handling module to be able to handle both |
Beta Was this translation helpful? Give feedback.
-
I often have the following verbose pattern in my code:
... especially in testing code.
For convenience sake I'd love to see something like this:
and even:
Because it's rather an easy implementation and I wanted to play around a little bit I've already implemented this here:
master...timofurrer:httpx:feature/raise-for-status
I'm already aware of the
event_hooks
, but I suppose the described use case is common enough to dedicate this non-intrusive, intuitive flag to it.WDYT?
Beta Was this translation helpful? Give feedback.
All reactions