diff --git a/supertokens_python/querier.py b/supertokens_python/querier.py index 8c8153c8d..99292bf09 100644 --- a/supertokens_python/querier.py +++ b/supertokens_python/querier.py @@ -77,10 +77,13 @@ async def api_request( self, url: str, method: str, - retry: bool, + retry_count: int, *args: Any, **kwargs: Any, ) -> Response: + if retry_count == 0: + raise_general_exception("Retry request failed") + try: async with AsyncClient() as client: if method == "GET": @@ -96,9 +99,10 @@ async def api_request( # Try one more time loop = create_or_get_event_loop() return loop.run_until_complete( - self.api_request(url, method, False, *args, **kwargs) + self.api_request(url, method, retry_count - 1, *args, **kwargs) ) + async def get_api_version(self): if Querier.api_version is not None: return Querier.api_version @@ -111,7 +115,7 @@ async def f(url: str, method: str) -> Response: headers = {} if Querier.__api_key is not None: headers = {API_KEY_HEADER: Querier.__api_key} - return await self.api_request(url, method, True, headers=headers) + return await self.api_request(url, method, 1, headers=headers) response = await self.__send_request_helper( NormalisedURLPath(API_VERSION), "GET", f, len(self.__hosts) @@ -165,7 +169,7 @@ async def f(url: str, method: str) -> Response: return await self.api_request( url, method, - True, + 1, headers=await self.__get_headers_with_api_version(path), params=params, ) @@ -195,7 +199,7 @@ async def f(url: str, method: str) -> Response: return await self.api_request( url, method, - True, + 1, headers=await self.__get_headers_with_api_version(path), json=data, ) @@ -212,7 +216,7 @@ async def f(url: str, method: str) -> Response: return await self.api_request( url, method, - True, + 1, headers=await self.__get_headers_with_api_version(path), params=params, ) @@ -229,7 +233,7 @@ async def send_put_request( headers["content-type"] = "application/json; charset=utf-8" async def f(url: str, method: str) -> Response: - return await self.api_request(url, method, True, headers=headers, json=data) + return await self.api_request(url, method, 1, headers=headers, json=data) return await self.__send_request_helper(path, "PUT", f, len(self.__hosts)) @@ -323,7 +327,6 @@ async def __send_request_helper( except JSONDecodeError: return response.text except (ConnectionError, NetworkError, ConnectTimeout) as _: - print("Retryingg!") return await self.__send_request_helper( path, method, http_function, no_of_tries - 1, retry_info_map ) diff --git a/supertokens_python/supertokens.py b/supertokens_python/supertokens.py index 2259c4da1..5e9814ff4 100644 --- a/supertokens_python/supertokens.py +++ b/supertokens_python/supertokens.py @@ -529,11 +529,6 @@ async def middleware( # pylint: disable=no-self-use async def handle_supertokens_error( self, request: BaseRequest, err: Exception, response: BaseResponse ): - import asyncio - - await asyncio.sleep(1) - # return send_non_200_response_with_message("err", 400, response) - log_debug_message("errorHandler: Started") log_debug_message( "errorHandler: Error is from SuperTokens recipe. Message: %s", str(err)