mirror of
https://github.com/ihabunek/toot
synced 2024-12-22 23:08:17 +01:00
Log request exceptions
This commit is contained in:
parent
9664d71b57
commit
57be6beae8
@ -3,7 +3,7 @@ from requests.exceptions import RequestException
|
||||
|
||||
from toot import __version__
|
||||
from toot.exceptions import NotFoundError, ApiError
|
||||
from toot.logging import log_request, log_response
|
||||
from toot.logging import log_request, log_request_exception, log_response
|
||||
|
||||
|
||||
def send_request(request, allow_redirects=True):
|
||||
@ -19,6 +19,7 @@ def send_request(request, allow_redirects=True):
|
||||
settings = session.merge_environment_settings(prepared.url, {}, None, None, None)
|
||||
response = session.send(prepared, allow_redirects=allow_redirects, **settings)
|
||||
except RequestException as ex:
|
||||
log_request_exception(request, ex)
|
||||
raise ApiError(f"Request failed: {str(ex)}")
|
||||
|
||||
log_response(response)
|
||||
|
@ -2,7 +2,7 @@ import json
|
||||
import sys
|
||||
|
||||
from logging import getLogger
|
||||
from requests import Request, Response
|
||||
from requests import Request, RequestException, Response
|
||||
from urllib.parse import urlencode
|
||||
|
||||
logger = getLogger("toot")
|
||||
@ -56,6 +56,10 @@ def log_response(response: Response):
|
||||
logger.debug(f" <-- {content}")
|
||||
|
||||
|
||||
def log_request_exception(request: Request, ex: RequestException):
|
||||
logger.debug(f" <-- {request.method} {_url(request)} Exception: {ex}")
|
||||
|
||||
|
||||
def _url(request):
|
||||
url = request.url
|
||||
if request.params:
|
||||
|
Loading…
Reference in New Issue
Block a user