(self, route: "Route")
| 422 | return url_matches(self._base_url, request_url, self.url) |
| 423 | |
| 424 | async def handle(self, route: "Route") -> bool: |
| 425 | handler_invocation = RouteHandlerInvocation( |
| 426 | asyncio.get_running_loop().create_future(), route |
| 427 | ) |
| 428 | self._active_invocations.add(handler_invocation) |
| 429 | try: |
| 430 | return await self._handle_internal(route) |
| 431 | except Exception as e: |
| 432 | # If the handler was stopped (without waiting for completion), we ignore all exceptions. |
| 433 | if self._ignore_exception: |
| 434 | return False |
| 435 | if is_target_closed_error(e): |
| 436 | # We are failing in the handler because the target has closed. |
| 437 | # Give user a hint! |
| 438 | optional_async_prefix = "await " if not self._is_sync else "" |
| 439 | raise rewrite_error( |
| 440 | e, |
| 441 | f"\"{str(e)}\" while running route callback.\nConsider awaiting `{optional_async_prefix}page.unroute_all(behavior='ignoreErrors')`\nbefore the end of the test to ignore remaining routes in flight.", |
| 442 | ) |
| 443 | raise e |
| 444 | finally: |
| 445 | handler_invocation.complete.set_result(None) |
| 446 | self._active_invocations.remove(handler_invocation) |
| 447 | |
| 448 | async def _handle_internal(self, route: "Route") -> bool: |
| 449 | handled_future = route._start_handling() |
no test coverage detected