diff --git a/standard_open_inflation_package/direct_request_interceptor.py b/standard_open_inflation_package/direct_request_interceptor.py index 0549833..28eb5dc 100644 --- a/standard_open_inflation_package/direct_request_interceptor.py +++ b/standard_open_inflation_package/direct_request_interceptor.py @@ -116,6 +116,14 @@ async def _handle_captured_response(self, handlers: List[Handler], response, req url=response.url, error=e )) + current_time = time.time() + for handler in handlers: + self.handler_errors[handler.slug] = HandlerSearchFailed( + rejected_responses=self.rejected_responses, + duration=current_time - self.start_time, + handler_slug=handler.slug, + ) + self._check_completion() def _handle_rejected_response(self, response, request, response_time: float): """Обрабатывает отклоненный response""" diff --git a/tests/api/interceptor_tests.py b/tests/api/interceptor_tests.py index c17cde4..51163f7 100644 --- a/tests/api/interceptor_tests.py +++ b/tests/api/interceptor_tests.py @@ -7,7 +7,8 @@ run_direct_fetch_test, run_page_resource_intercept_test, run_no_intercept_test, - assert_success_result, + assert_success_result, + assert_failed_result, assert_html_content, api_session, DEFAULT_TIMEOUT, @@ -202,3 +203,20 @@ def check_audio_content(response): additional_checks=check_audio_content, min_resources=1 ) + + +@pytest.mark.asyncio +async def test_handler_error_marks_failed(monkeypatch): + """Ensure handler errors are reported as failures.""" + import standard_open_inflation_package.direct_request_interceptor as interceptor + + def raise_error(*args, **kwargs): + raise RuntimeError("boom") + + monkeypatch.setattr(interceptor, "parse_response_data", raise_error) + + async with api_session(DEFAULT_TIMEOUT) as api: + results = await api.new_direct_fetch(CHECK_HTML_PAGE, handlers=Handler.MAIN()) + + assert len(results) == 1 + assert_failed_result(results[0], min_rejected=0)