|
1 | 1 | from json import JSONDecodeError |
2 | 2 | from typing import Union |
3 | 3 |
|
4 | | -from requests import Response |
| 4 | +from requests import Response, RequestException |
5 | 5 |
|
6 | 6 |
|
7 | | -class AuthenticationFailed(Exception): |
| 7 | +class RequestsAuthException(RequestException): ... |
| 8 | + |
| 9 | + |
| 10 | +class AuthenticationFailed(RequestsAuthException): |
8 | 11 | """User was not authenticated.""" |
9 | 12 |
|
10 | 13 | def __init__(self): |
11 | | - Exception.__init__(self, "User was not authenticated.") |
| 14 | + RequestsAuthException.__init__(self, "User was not authenticated.") |
12 | 15 |
|
13 | 16 |
|
14 | | -class TimeoutOccurred(Exception): |
| 17 | +class TimeoutOccurred(RequestsAuthException): |
15 | 18 | """No response within timeout interval.""" |
16 | 19 |
|
17 | 20 | def __init__(self, timeout: float): |
18 | | - Exception.__init__( |
| 21 | + RequestsAuthException.__init__( |
19 | 22 | self, f"User authentication was not received within {timeout} seconds." |
20 | 23 | ) |
21 | 24 |
|
22 | 25 |
|
23 | | -class InvalidToken(Exception): |
| 26 | +class InvalidToken(RequestsAuthException): |
24 | 27 | """Token is invalid.""" |
25 | 28 |
|
26 | 29 | def __init__(self, token_name: str): |
27 | | - Exception.__init__(self, f"{token_name} is invalid.") |
| 30 | + RequestsAuthException.__init__(self, f"{token_name} is invalid.") |
28 | 31 |
|
29 | 32 |
|
30 | | -class GrantNotProvided(Exception): |
| 33 | +class GrantNotProvided(RequestsAuthException): |
31 | 34 | """Grant was not provided.""" |
32 | 35 |
|
33 | 36 | def __init__(self, grant_name: str, dictionary_without_grant: dict): |
34 | | - Exception.__init__( |
| 37 | + RequestsAuthException.__init__( |
35 | 38 | self, f"{grant_name} not provided within {dictionary_without_grant}." |
36 | 39 | ) |
37 | 40 |
|
38 | 41 |
|
39 | | -class InvalidGrantRequest(Exception): |
| 42 | +class InvalidGrantRequest(RequestsAuthException): |
40 | 43 | """ |
41 | 44 | If the request failed client authentication or is invalid, the authorization server returns an error response as described in https://tools.ietf.org/html/rfc6749#section-5.2 |
42 | 45 | """ |
@@ -64,7 +67,7 @@ class InvalidGrantRequest(Exception): |
64 | 67 | } |
65 | 68 |
|
66 | 69 | def __init__(self, response: Union[Response, dict]): |
67 | | - Exception.__init__(self, InvalidGrantRequest.to_message(response)) |
| 70 | + RequestsAuthException.__init__(self, InvalidGrantRequest.to_message(response)) |
68 | 71 |
|
69 | 72 | @staticmethod |
70 | 73 | def to_message(response: Union[Response, dict]) -> str: |
@@ -114,17 +117,19 @@ def _pop(key: str) -> str: |
114 | 117 | return message |
115 | 118 |
|
116 | 119 |
|
117 | | -class StateNotProvided(Exception): |
| 120 | +class StateNotProvided(RequestsAuthException): |
118 | 121 | """State was not provided.""" |
119 | 122 |
|
120 | 123 | def __init__(self, dictionary_without_state: dict): |
121 | | - Exception.__init__( |
| 124 | + RequestsAuthException.__init__( |
122 | 125 | self, f"state not provided within {dictionary_without_state}." |
123 | 126 | ) |
124 | 127 |
|
125 | 128 |
|
126 | | -class TokenExpiryNotProvided(Exception): |
| 129 | +class TokenExpiryNotProvided(RequestsAuthException): |
127 | 130 | """Token expiry was not provided.""" |
128 | 131 |
|
129 | 132 | def __init__(self, token_body: dict): |
130 | | - Exception.__init__(self, f"Expiry (exp) is not provided in {token_body}.") |
| 133 | + RequestsAuthException.__init__( |
| 134 | + self, f"Expiry (exp) is not provided in {token_body}." |
| 135 | + ) |
0 commit comments