Skip to content

Commit fff00e1

Browse files
committed
feat: introduce AuthConnectionError for connection errors
This makes it possible to handle these specifically in the caller. Fixes #916
1 parent e17440d commit fff00e1

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ ignore = [
127127
"B018", # TODO: Found useless expression.
128128
"A001", # TODO: Variable is shadowing a Python builtin
129129
"A002", # TODO: Function argument is shadowing a Python builtin
130-
"A004", # TODO: Import `ConnectionError` is shadowing a Python builtin
131130
"ERA001", # TODO: Found commented-out code
132131
"EM101", # TODO: Exception must not use a string literal, assign to variable first
133132
"EM102", # TODO: Exception must not use an f-string literal, assign to variable first

social_core/backends/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import time
22
from typing import Any
33

4-
from requests import ConnectionError, request
4+
import requests
55

6-
from ..exceptions import AuthFailed
6+
from ..exceptions import AuthConnectionError
77
from ..utils import module_member, parse_qs, user_agent
88

99

@@ -236,9 +236,9 @@ def request(self, url, method="GET", *args, **kwargs):
236236
kwargs["headers"]["User-Agent"] = self.setting("USER_AGENT") or user_agent()
237237

238238
try:
239-
response = request(method, url, *args, **kwargs)
240-
except ConnectionError as err:
241-
raise AuthFailed(self, str(err))
239+
response = requests.request(method, url, *args, **kwargs)
240+
except requests.ConnectionError as err:
241+
raise AuthConnectionError(self, str(err)) from err
242242
response.raise_for_status()
243243
return response
244244

social_core/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,11 @@ def __str__(self):
126126
class InvalidEmail(AuthException):
127127
def __str__(self):
128128
return "Email couldn't be validated"
129+
130+
131+
class AuthConnectionError(AuthException):
132+
"""Connection error duing authentication."""
133+
134+
def __str__(self):
135+
msg = super().__str__()
136+
return f"Connection error: {msg}"

0 commit comments

Comments
 (0)