File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -255,6 +255,7 @@ async def handler() -> str:
255255 body = resp .json ()
256256 assert body ["success" ] is False
257257 assert body ["error" ] == "Method Not Allowed"
258+ assert "POST" in resp .headers .get ("allow" , "" )
258259
259260 def test_http_exception_5xx_returns_scrubbed_message (self ) -> None :
260261 """5xx HTTPException scrubs detail to prevent info leakage."""
@@ -285,3 +286,22 @@ async def handler() -> None:
285286 assert resp .status_code == 429
286287 body = resp .json ()
287288 assert body ["error" ] == "Too Many Requests"
289+
290+ def test_http_exception_nonstandard_status_uses_fallback (self ) -> None :
291+ """Non-standard status code falls back to generic message."""
292+ from unittest .mock import MagicMock
293+
294+ from ai_company .api .exception_handlers import handle_http_exception
295+
296+ exc = MagicMock (spec = HTTPException )
297+ exc .status_code = 499
298+ exc .detail = ""
299+ exc .headers = None
300+
301+ request = MagicMock ()
302+ request .method = "GET"
303+ request .url .path = "/test"
304+
305+ resp = handle_http_exception (request , exc )
306+ assert resp .status_code == 499
307+ assert resp .content .error == "Request error" # type: ignore[union-attr]
You can’t perform that action at this time.
0 commit comments