2626
2727try :
2828 import gql
29+ import gql .transport .exceptions
2930 import graphql
3031 import httpx
3132
@@ -746,7 +747,9 @@ def http_request(
746747 if 200 <= result .status_code < 300 :
747748 return result .response
748749
749- if retry .handle_retry_on_status (result ):
750+ if retry .handle_retry_on_status (
751+ result .status_code , result .headers , result .reason
752+ ):
750753 continue
751754
752755 error_message = result .content
@@ -1284,6 +1287,9 @@ def __init__(
12841287 timeout : Optional [float ] = None ,
12851288 user_agent : str = gitlab .const .USER_AGENT ,
12861289 fetch_schema_from_transport : bool = False ,
1290+ max_retries : int = 10 ,
1291+ obey_rate_limit : bool = True ,
1292+ retry_transient_errors : bool = False ,
12871293 ) -> None :
12881294 if not _GQL_INSTALLED :
12891295 raise ImportError (
@@ -1297,6 +1303,9 @@ def __init__(
12971303 self ._url = f"{ self ._base_url } /api/graphql"
12981304 self ._user_agent = user_agent
12991305 self ._ssl_verify = ssl_verify
1306+ self ._max_retries = max_retries
1307+ self ._obey_rate_limit = obey_rate_limit
1308+ self ._retry_transient_errors = retry_transient_errors
13001309
13011310 opts = self ._get_client_opts ()
13021311 self ._http_client = client or httpx .Client (** opts )
@@ -1329,4 +1338,30 @@ def execute(
13291338 self , request : Union [str , graphql .Source ], * args : Any , ** kwargs : Any
13301339 ) -> Any :
13311340 parsed_document = self ._gql (request )
1332- return self ._client .execute (parsed_document , * args , ** kwargs )
1341+ retry = utils .Retry (
1342+ max_retries = self ._max_retries ,
1343+ obey_rate_limit = self ._obey_rate_limit ,
1344+ retry_transient_errors = self ._retry_transient_errors ,
1345+ )
1346+
1347+ while True :
1348+ try :
1349+ result = self ._client .execute (parsed_document , * args , ** kwargs )
1350+ except gql .transport .exceptions .TransportServerError as e :
1351+ if retry .handle_retry_on_status (
1352+ status_code = e .code , headers = self ._transport .response_headers
1353+ ):
1354+ continue
1355+
1356+ if e .code == 401 :
1357+ raise gitlab .exceptions .GitlabAuthenticationError (
1358+ response_code = e .code ,
1359+ error_message = str (e ),
1360+ )
1361+
1362+ raise gitlab .exceptions .GitlabHttpError (
1363+ response_code = e .code ,
1364+ error_message = str (e ),
1365+ )
1366+
1367+ return result
0 commit comments