Coverage for api_client/exceptions.py: 66.67%

12 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2026-04-15 13:02 +0000

1"""Custom exceptions for API client.""" 

2 

3 

4class APIError(Exception): 

5 """Base exception for API errors.""" 

6 

7 def __init__(self, message: str, status_code: int | None = None, response_data: dict | None = None): 

8 self.message = message 

9 self.status_code = status_code 

10 self.response_data = response_data 

11 super().__init__(self.message) 

12 

13 

14class AuthenticationError(APIError): 

15 """Raised when authentication fails (401).""" 

16 

17 pass 

18 

19 

20class AuthorizationError(APIError): 

21 """Raised when authorization fails (403).""" 

22 

23 pass 

24 

25 

26class NotFoundError(APIError): 

27 """Raised when resource is not found (404).""" 

28 

29 pass 

30 

31 

32class ValidationError(APIError): 

33 """Raised when validation fails (422).""" 

34 

35 pass 

36 

37 

38class RateLimitError(APIError): 

39 """Raised when rate limit is exceeded (429).""" 

40 

41 pass 

42 

43 

44class ServerError(APIError): 

45 """Raised when server returns 5xx error.""" 

46 

47 pass