Locate response container and text elements, including timeout and error handling.
(
page: AsyncPage,
req_id: str,
logger: logging.Logger,
check_client_disconnected: Callable[[str], bool],
)
| 10 | |
| 11 | |
| 12 | async def locate_response_elements( |
| 13 | page: AsyncPage, |
| 14 | req_id: str, |
| 15 | logger: logging.Logger, |
| 16 | check_client_disconnected: Callable[[str], bool], |
| 17 | ) -> None: |
| 18 | """Locate response container and text elements, including timeout and error handling.""" |
| 19 | logger.info(f"[{req_id}] Locating response elements...") |
| 20 | response_container = page.locator(RESPONSE_CONTAINER_SELECTOR).last |
| 21 | response_element = response_container.locator(RESPONSE_TEXT_SELECTOR) |
| 22 | |
| 23 | try: |
| 24 | await expect_async(response_container).to_be_attached(timeout=20000) |
| 25 | check_client_disconnected("After Response Container Attached: ") |
| 26 | await expect_async(response_element).to_be_attached(timeout=90000) |
| 27 | logger.info(f"[{req_id}] Response elements located.") |
| 28 | except (PlaywrightAsyncError, asyncio.TimeoutError) as locate_err: |
| 29 | from .error_utils import upstream_error |
| 30 | |
| 31 | raise upstream_error( |
| 32 | req_id, f"Failed to locate AI Studio response elements: {locate_err}" |
| 33 | ) |
| 34 | except Exception as locate_exc: |
| 35 | from .error_utils import server_error |
| 36 | |
| 37 | raise server_error( |
| 38 | req_id, f"Unexpected error while locating response elements: {locate_exc}" |
| 39 | ) |