-
-
Notifications
You must be signed in to change notification settings - Fork 575
Expand file tree
/
Copy pathexceptions.py
More file actions
201 lines (124 loc) · 5.49 KB
/
Copy pathexceptions.py
File metadata and controls
201 lines (124 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from social_core.backends.base import BaseAuth
class SocialAuthBaseException(ValueError):
"""Base class for pipeline exceptions."""
class SocialAuthImproperlyConfiguredError(SocialAuthBaseException):
"""Raised when configuration is invalid."""
class StrategyMissingFeatureError(SocialAuthBaseException):
"""Strategy does not support this."""
def __init__(self, strategy_name: str, feature_name: str) -> None:
self.strategy_name = strategy_name
self.feature_name = feature_name
super().__init__()
def __str__(self) -> str:
return f"Strategy {self.strategy_name} does not support {self.feature_name}"
class DefaultStrategyMissingError(SocialAuthBaseException):
"""Default strategy is not configured."""
def __str__(self) -> str:
return "Default strategy is not configured"
class StrategyMissingBackendError(SocialAuthBaseException):
"""Strategy storage backend is not configured."""
def __str__(self) -> str:
return "Strategy storage backend is not configured"
class WrongBackend(SocialAuthBaseException):
def __init__(self, backend_name: str) -> None:
self.backend_name = backend_name
super().__init__()
def __str__(self) -> str:
return f'Incorrect authentication service "{self.backend_name}"'
class MissingBackend(WrongBackend):
def __str__(self) -> str:
return f'Missing backend "{self.backend_name}" entry'
class NotAllowedToDisconnect(SocialAuthBaseException):
"""User is not allowed to disconnect it's social account."""
def __str__(self) -> str:
return "This account is not allowed to be disconnected."
class AuthException(SocialAuthBaseException):
"""Auth process exception."""
def __init__(self, backend: BaseAuth, *args, **kwargs) -> None:
self.backend = backend
super().__init__(*args, **kwargs)
class AuthFailed(AuthException):
"""Auth process failed for some reason."""
def __str__(self) -> str:
msg = super().__str__()
if msg == "access_denied":
return "Authentication process was canceled"
return f"Authentication failed: {msg}"
class AuthCanceled(AuthException):
"""Auth process was canceled by user."""
def __init__(self, *args, **kwargs) -> None:
self.response = kwargs.pop("response", None)
super().__init__(*args, **kwargs)
def __str__(self) -> str:
msg = super().__str__()
if msg:
return f"Authentication process canceled: {msg}"
return "Authentication process canceled"
class AuthUnknownError(AuthException):
"""Unknown auth process error."""
def __str__(self) -> str:
msg = super().__str__()
return f"An unknown error happened while authenticating {msg}"
class AuthTokenError(AuthException):
"""Auth token error."""
def __str__(self) -> str:
msg = super().__str__()
return f"Token error: {msg}"
class AuthMissingParameter(AuthException):
"""Missing parameter needed to start or complete the process."""
def __init__(self, backend: BaseAuth, parameter: str, *args, **kwargs) -> None:
self.parameter = parameter
super().__init__(backend, *args, **kwargs)
def __str__(self) -> str:
return f"Missing needed parameter {self.parameter}"
class AuthInvalidParameter(AuthMissingParameter):
"""Invalid value for parameter to start or complete the process."""
def __str__(self) -> str:
return f"Invalid value for parameter {self.parameter}"
class AuthNotImplementedParameter(AuthMissingParameter):
"""Optional parameter not implemented to start or complete the process."""
def __str__(self) -> str:
return f"Not implemented parameter {self.parameter}"
class AuthStateMissing(AuthException):
"""State parameter is incorrect."""
def __str__(self) -> str:
return "Session value state missing."
class AuthStateForbidden(AuthException):
"""State parameter is incorrect."""
def __str__(self) -> str:
return "Wrong state parameter given."
class AuthAlreadyAssociated(AuthException):
"""A different user has already associated the target social account"""
def __str__(self) -> str:
return "This account is already in use."
class AuthTokenRevoked(AuthException):
"""User revoked the access_token in the provider."""
def __str__(self) -> str:
return "User revoke access to the token"
class AuthForbidden(AuthException):
"""Authentication for this user is forbidden"""
def __str__(self) -> str:
return "Your credentials aren't allowed"
class AuthUnreachableProvider(AuthException):
"""Cannot reach the provider"""
def __str__(self) -> str:
return "The authentication provider could not be reached"
class InvalidEmail(AuthException):
def __str__(self) -> str:
return "Email couldn't be validated"
class AuthConnectionError(AuthException):
"""Connection error duing authentication."""
def __str__(self) -> str:
msg = super().__str__()
return f"Connection error: {msg}"
class InvalidExpiryValue(SocialAuthBaseException):
"""Invalid expiry value in extra_data."""
def __init__(self, field_name: str, value: object) -> None:
self.field_name = field_name
self.value = value
super().__init__()
def __str__(self) -> str:
return f"Invalid expiry value for field '{self.field_name}': {self.value}"