11import os
22from typing import Any
33
4- from httpx import AsyncClient , HTTPError , HTTPStatusError
4+ from httpx import AsyncClient , HTTPError , HTTPStatusError , RequestError
55from httpx_retries import Retry , RetryTransport
66
77from mpt_api_client .constants import APPLICATION_JSON
8- from mpt_api_client .exceptions import MPTError , transform_http_status_exception
8+ from mpt_api_client .exceptions import MPTError , MPTMaxRetryError , transform_http_status_exception
99from mpt_api_client .http .client import json_to_file_payload
1010from mpt_api_client .http .client_utils import get_query_params , validate_base_url
1111from mpt_api_client .http .query_options import QueryOptions
@@ -23,6 +23,7 @@ def __init__(
2323 timeout : float = 20.0 ,
2424 retries : int = 5 ,
2525 ):
26+ self ._retries = retries
2627 retry = Retry (total = retries )
2728 transport = RetryTransport (retry = retry )
2829
@@ -47,7 +48,7 @@ def __init__(
4748 follow_redirects = True ,
4849 )
4950
50- async def request ( # noqa: WPS211
51+ async def request ( # noqa: WPS211 # NOSONAR
5152 self ,
5253 method : str ,
5354 url : str ,
@@ -80,6 +81,7 @@ async def request( # noqa: WPS211
8081 MPTError: If the request fails.
8182 MPTApiError: If the response contains an error.
8283 MPTHttpError: If the response contains an HTTP error.
84+ MPTMaxRetryError: If the request fails after maximum retry attempts.
8385 """
8486 files = dict (files or {})
8587 if force_multipart or (files and json ):
@@ -95,6 +97,8 @@ async def request( # noqa: WPS211
9597 params = params_str or None ,
9698 headers = headers ,
9799 )
100+ except RequestError as err :
101+ raise MPTMaxRetryError (str (err ), self ._retries + 1 ) from err
98102 except HTTPError as err :
99103 raise MPTError (f"HTTP Error: { err } " ) from err
100104
0 commit comments