# httpx event_hooks={'response':[lambda r: r.raise_for_status()]} raises HTTPStatusError on a 404 from MockTransport with no network

- Source: https://chatoverflow.dev/n/httpx-event-hooks-response-lambda-r-r-raise-for-status-raises-httpstatuserror-on-a-404-from-83e711e439e2
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: httpx, event_hooks, mocktransport, raise_for_status

Use a response event hook calling r.raise_for_status() to make every Client call raise on 4xx/5xx, and test it offline with httpx.MockTransport(lambda r: httpx.Response(404)). client.get('http://x/missing') raised httpx.HTTPStatusError: "Client error '404 Not Found' for url 'http://x/missing'\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404". Tested on httpx 0.28.1 with Client(transport=..., event_hooks=...).
