| 
									
										
										
										
											2025-01-25 00:11:00 +01:00
										 |  |  | import httpx | 
					
						
							|  |  |  | from typing import Literal | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-25 00:55:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-25 00:11:00 +01:00
										 |  |  | class APIStatusError(Exception): | 
					
						
							|  |  |  |     """Raised when an API response has a status code of 4xx or 5xx.""" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response: httpx.Response | 
					
						
							|  |  |  |     status_code: int | 
					
						
							|  |  |  |     request_id: str | None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-25 00:55:07 +01:00
										 |  |  |     def __init__( | 
					
						
							|  |  |  |         self, message: str, *, response: httpx.Response, body: object | None | 
					
						
							|  |  |  |     ) -> None: | 
					
						
							| 
									
										
										
										
											2025-01-25 00:11:00 +01:00
										 |  |  |         super().__init__(message, response.request, body=body) | 
					
						
							|  |  |  |         self.response = response | 
					
						
							|  |  |  |         self.status_code = response.status_code | 
					
						
							|  |  |  |         self.request_id = response.headers.get("x-request-id") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-25 00:55:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-25 00:11:00 +01:00
										 |  |  | class APIConnectionError(Exception): | 
					
						
							| 
									
										
										
										
											2025-01-25 00:55:07 +01:00
										 |  |  |     def __init__( | 
					
						
							|  |  |  |         self, *, message: str = "Connection error.", request: httpx.Request | 
					
						
							|  |  |  |     ) -> None: | 
					
						
							| 
									
										
										
										
											2025-01-25 00:11:00 +01:00
										 |  |  |         super().__init__(message, request, body=None) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BadRequestError(APIStatusError): | 
					
						
							|  |  |  |     status_code: Literal[400] = 400  # pyright: ignore[reportIncompatibleVariableOverride] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AuthenticationError(APIStatusError): | 
					
						
							|  |  |  |     status_code: Literal[401] = 401  # pyright: ignore[reportIncompatibleVariableOverride] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PermissionDeniedError(APIStatusError): | 
					
						
							|  |  |  |     status_code: Literal[403] = 403  # pyright: ignore[reportIncompatibleVariableOverride] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NotFoundError(APIStatusError): | 
					
						
							|  |  |  |     status_code: Literal[404] = 404  # pyright: ignore[reportIncompatibleVariableOverride] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ConflictError(APIStatusError): | 
					
						
							|  |  |  |     status_code: Literal[409] = 409  # pyright: ignore[reportIncompatibleVariableOverride] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class UnprocessableEntityError(APIStatusError): | 
					
						
							|  |  |  |     status_code: Literal[422] = 422  # pyright: ignore[reportIncompatibleVariableOverride] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class RateLimitError(APIStatusError): | 
					
						
							|  |  |  |     status_code: Literal[429] = 429  # pyright: ignore[reportIncompatibleVariableOverride] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-25 00:55:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-25 00:11:00 +01:00
										 |  |  | class APITimeoutError(APIConnectionError): | 
					
						
							|  |  |  |     def __init__(self, request: httpx.Request) -> None: | 
					
						
							|  |  |  |         super().__init__(message="Request timed out.", request=request) |