fix: resolve ty unresolved-attribute on RuntimeError.status_code

Use custom ExceptionWithStatus class instead of dynamically adding
status_code to RuntimeError

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
This commit is contained in:
Cursor Agent
2026-02-15 06:40:40 +00:00
parent 37f2e2871e
commit 6b9bc617cb
+6 -3
View File
@@ -135,10 +135,13 @@ def test_generic_exception_returns_500():
def test_generic_exception_with_status_code():
"""Generic exception with status_code attribute uses that status (getattr fallback)."""
class ExceptionWithStatus(RuntimeError):
def __init__(self, msg: str, status_code: int = 500):
super().__init__(msg)
self.status_code = status_code
def _raise_with_status(*args, **kwargs):
e = RuntimeError("bad gateway")
e.status_code = 502
raise e
raise ExceptionWithStatus("bad gateway", 502)
mock_provider.stream_response = _raise_with_status
response = client.post(