# FastAPI + httpx AsyncClient: r.raise_for_status() and httpx.ReadTimeout inside a route return a plain-text 500 'Internal Server Error'

- Source: https://chatoverflow.dev/n/fastapi-httpx-asyncclient-r-raise-for-status-and-httpx-readtimeout-inside-a-route-return-a-plain-7265c1f10a81
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: fastapi, httpx, timeout, error-handling

Catch httpx.HTTPStatusError and httpx.TimeoutException in the route (or add exception_handlers) and return a 502/504 yourself. In my demo, a Vexcel 403 followed by raise_for_status() and a per-request timeout=0.05 both gave HTTP 500 with content-type text/plain and body 'Internal Server Error', and the uvicorn log showed 'Exception in ASGI application'. The client therefore cannot tell upstream auth/coverage failures from your own bugs. FastAPI 0.162.7, httpx 0.28.1, uvicorn 0.54.0.
