diff --git a/src/infrastructure/beorg/client.py b/src/infrastructure/beorg/client.py index 0fdb84e..5e249b1 100644 --- a/src/infrastructure/beorg/client.py +++ b/src/infrastructure/beorg/client.py @@ -18,7 +18,7 @@ class BeorgService(IBeorgService): machine_uid: str, token: str, process_info: list[dict[str,Any]], - timeout: int = 15, + timeout: int = 120, ) -> None: self._project_id = project_id self._machine_uid = machine_uid @@ -38,13 +38,18 @@ class BeorgService(IBeorgService): } timeout = aiohttp.ClientTimeout(total=self._timeout) - async with aiohttp.ClientSession(timeout=timeout) as session: - async with session.post( - f'{self.BASE_URL}{self.CREATE_ENDPOINT}', - json=payload, - headers={'Content-Type': 'application/json'}, - ) as response: - data = await response.json(content_type=None) + try: + async with aiohttp.ClientSession(timeout=timeout) as session: + async with session.post( + f'{self.BASE_URL}{self.CREATE_ENDPOINT}', + json=payload, + headers={'Content-Type': 'application/json'}, + ) as response: + data = await response.json(content_type=None) + except TimeoutError: + raise BeorgUnavailableException() from None + except aiohttp.ClientError: + raise BeorgUnavailableException() from None if response.status >= 500: raise BeorgUnavailableException() @@ -59,16 +64,21 @@ class BeorgService(IBeorgService): async def get_result(self,user_token: str) -> BeorgKycResultResponse: self._ensure_configured() timeout = aiohttp.ClientTimeout(total=self._timeout) - async with aiohttp.ClientSession(timeout=timeout) as session: - async with session.get( - f'{self.BASE_URL}{self.GET_RESULT_ENDPOINT}', - params={ - 'token': self._token, - 'user_token': user_token, - }, - headers={'Content-Type': 'application/json'}, - ) as response: - data = await response.json(content_type=None) + try: + async with aiohttp.ClientSession(timeout=timeout) as session: + async with session.get( + f'{self.BASE_URL}{self.GET_RESULT_ENDPOINT}', + params={ + 'token': self._token, + 'user_token': user_token, + }, + headers={'Content-Type': 'application/json'}, + ) as response: + data = await response.json(content_type=None) + except TimeoutError: + raise BeorgUnavailableException() from None + except aiohttp.ClientError: + raise BeorgUnavailableException() from None if response.status >= 500: raise BeorgUnavailableException() diff --git a/src/infrastructure/config/settings.py b/src/infrastructure/config/settings.py index b5278a9..78d8ea3 100644 --- a/src/infrastructure/config/settings.py +++ b/src/infrastructure/config/settings.py @@ -39,7 +39,7 @@ class Settings(BaseSettings): KYC_POLL_SECONDS: int = 10 KYC_POLL_BATCH_SIZE: int = 20 EXCLUDED_PATHS: tuple[str,...] = ('/docs','/redoc','/openapi.json','/ping') - BEORG_TIMEOUT: int = 15 + BEORG_TIMEOUT: int = 120 BEORG_PROCESS_INFO: list[dict[str,Any]] = Field(default_factory=lambda: [ { 'key': 'SELFIE1',