1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-11-03 04:17:21 -05:00

Catch request errors

This commit is contained in:
Ivan Habunek 2022-11-22 21:19:52 +01:00
parent f299af3a1a
commit 1b84f34123
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95

View File

@ -1,4 +1,6 @@
from requests import Request, Session
from requests.exceptions import RequestException
from toot import __version__
from toot.exceptions import NotFoundError, ApiError
from toot.logging import log_request, log_response
@ -11,10 +13,13 @@ def send_request(request, allow_redirects=True):
log_request(request)
with Session() as session:
prepared = session.prepare_request(request)
settings = session.merge_environment_settings(prepared.url, {}, None, None, None)
response = session.send(prepared, allow_redirects=allow_redirects, **settings)
try:
with Session() as session:
prepared = session.prepare_request(request)
settings = session.merge_environment_settings(prepared.url, {}, None, None, None)
response = session.send(prepared, allow_redirects=allow_redirects, **settings)
except RequestException as ex:
raise ApiError(f"Request failed: {str(ex)}")
log_response(response)