Support Client-Level Exception Handlers for httpx.Client and httpx.AsyncClient #3701
Unanswered
dhruvjain1512
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🚀 Feature Request: Client-Level Exception Handlers for
httpx.Clientandhttpx.AsyncClientProblem Statement
Currently,
httpx.Clientandhttpx.AsyncClientdo not support registering custom exception handlers at the client level.Developers are forced to wrap every request call with repetitive
try/exceptblocks whenever consistent error handling is required.This results in:
In many real-world scenarios, applications need uniform exception management across all outgoing HTTP calls from a shared client instance.
Proposed Solution
Introduce the ability to register custom exception handlers at the client level, allowing centralized and automatic handling of all exceptions raised during requests.
Key aspects of the proposed behavior:
Example Use Case
This pattern ensures that all requests from a client share the same consistent error handling behavior without requiring per-call wrappers.
Expected Behavior
client.request(),client.get(),client.post(), etc.httpx.ReadTimeout) take precedence over general ones (e.g.,httpx.RequestError).Benefits
Discussion Points
exception_handlersbe modifiable post client initialization?References & Inspiration
exception_handlers), aiohttp middlewares, and requests-hooks.Beta Was this translation helpful? Give feedback.
All reactions