1"""
2Errors
3======
4
5"""
6
7from typing import Optional
8
9
10class GeoIP2Error(RuntimeError):
11    """There was a generic error in GeoIP2.
12
13    This class represents a generic error. It extends :py:exc:`RuntimeError`
14    and does not add any additional attributes.
15
16    """
17
18
19class AddressNotFoundError(GeoIP2Error):
20    """The address you were looking up was not found."""
21
22
23class AuthenticationError(GeoIP2Error):
24    """There was a problem authenticating the request."""
25
26
27class HTTPError(GeoIP2Error):
28    """There was an error when making your HTTP request.
29
30    This class represents an HTTP transport error. It extends
31    :py:exc:`GeoIP2Error` and adds attributes of its own.
32
33    :ivar http_status: The HTTP status code returned
34    :ivar uri: The URI queried
35    :ivar decoded_content: The decoded response content
36
37    """
38
39    def __init__(
40        self,
41        message: str,
42        http_status: Optional[int] = None,
43        uri: Optional[str] = None,
44        decoded_content: Optional[str] = None,
45    ) -> None:
46        super().__init__(message)
47        self.http_status = http_status
48        self.uri = uri
49        self.decoded_content = decoded_content
50
51
52class InvalidRequestError(GeoIP2Error):
53    """The request was invalid."""
54
55
56class OutOfQueriesError(GeoIP2Error):
57    """Your account is out of funds for the service queried."""
58
59
60class PermissionRequiredError(GeoIP2Error):
61    """Your account does not have permission to access this service."""
62