utils: add missing warning log on network error (#85742)
gitea/combo/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2024-01-16 17:17:33 +01:00
parent 253ae3863b
commit 7aff4544fc
1 changed files with 10 additions and 1 deletions

View File

@ -26,6 +26,7 @@ from django.utils.http import urlencode
from requests import Response
from requests import Session as RequestsSession
from requests.auth import AuthBase
from requests.exceptions import RequestException
from .misc import get_known_service_for_url
from .signature import sign_url
@ -162,7 +163,15 @@ class Requests(RequestsSession):
if method == 'GET' and cache_duration:
cache.set('%s_called' % cache_key, True, cache_duration)
response = super().request(method, url, **kwargs)
try:
response = super().request(method, url, **kwargs)
except RequestException as e:
if log_errors:
extra = {}
if django_request:
extra['request'] = django_request
logging.warning('failed to %s %s (%s)', method, url, e, extra=extra)
raise
if method == 'GET' and cache_duration:
cache.delete('%s_called' % cache_key)
if log_errors and (response.status_code // 100 != 2):