Coverage for src/usaspending/exceptions.py: 92%
24 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-03 17:15 -0700
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-03 17:15 -0700
1"""Custom exceptions for USASpending API client."""
4class USASpendingError(Exception):
5 """Base exception for all USASpending client errors."""
6 pass
9class APIError(USASpendingError):
10 """Raised when the API returns an error response."""
12 def __init__(
13 self, message: str, status_code: int = None, response_body: dict = None
14 ):
15 super().__init__(message)
16 self.status_code = status_code
17 self.response_body = response_body
20class HTTPError(USASpendingError):
21 """Raised when an HTTP error occurs."""
23 def __init__(self, message: str, status_code: int):
24 super().__init__(message)
25 self.status_code = status_code
28class RateLimitError(USASpendingError):
29 """Raised when rate limit is exceeded."""
31 def __init__(self, message: str = "Rate limit exceeded", retry_after: int = None):
32 super().__init__(message)
33 self.retry_after = retry_after
36class ValidationError(USASpendingError):
37 """Raised when input validation fails."""
39 pass
42class ConfigurationError(USASpendingError):
43 """Raised when client configuration is invalid."""
45 pass
47class DownloadError(USASpendingError):
48 """Raised when an award download process fails, times out, or encounters issues during file processing."""
49 def __init__(self, message: str, file_name: str = None, status: str = None):
50 super().__init__(message)
51 self.file_name = file_name
52 self.status = status