refactor: add exceptions.py module with structured exception hierarchy

- Create exceptions.py with 7 exception types: TwitterError, AuthenticationError,
  RateLimitError, NotFoundError, NetworkError, QueryIdError, TwitterAPIError
- Remove inline TwitterAPIError from client.py, import from exceptions module
- Replace RuntimeError('Cannot resolve queryId') with QueryIdError
- Replace RuntimeError('User not found') with NotFoundError
- Update test assertion for new TwitterAPIError message format
This commit is contained in:
jackwener
2026-03-10 23:05:05 +08:00
parent 9cf74abd56
commit 4afc4fc246
3 changed files with 56 additions and 9 deletions

View File

@@ -463,7 +463,7 @@ class TestTwitterAPIError:
def test_stores_status_code(self):
err = TwitterAPIError(429, "Rate limited")
assert err.status_code == 429
assert str(err) == "Rate limited"
assert "Rate limited" in str(err)
def test_is_runtime_error(self):
err = TwitterAPIError(500, "Server error")