requests
requests copied to clipboard
an idea on persisting redirect history when exceptions are encountered
this is a quick idea on an approach to address #4455
within resolve_redirects
exceptions raised bySession.send
are caught. If they match a given set of tests (currently just the base ConnectionError
class), the resp
is replaced with an instance of an exception class used to hold bad response data. Then a new exception is raised.
This makes handling these types of errors similar to handling items without redirects for most users (i did not consider the legacy ways of using requests)
The immediate ideas/concerns I have on this:
-
It might make sense to have a global "NotARealResponse" object that stands in for a
Response
object and can contain connection/history info when there is no immediate response. I'm not sure this is the only use-case for this. -
I thought about extending the current exception with request/response data, but this seemed more appropriate.
Just to be clear, this is only submitted for discussion/illustration of the other ticket. This is not a PR for merging.
Codecov Report
Merging #4456 into master will decrease coverage by
0.25%
. The diff coverage is66.66%
.
@@ Coverage Diff @@
## master #4456 +/- ##
==========================================
- Coverage 90.14% 89.89% -0.26%
==========================================
Files 15 15
Lines 1543 1554 +11
==========================================
+ Hits 1391 1397 +6
- Misses 152 157 +5
Impacted Files | Coverage Δ | |
---|---|---|
requests/sessions.py | 93.95% <66.66%> (-1.61%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update c98e30b...9dc04b3. Read the comment docs.