Skip to content

Fix/streaming error handling #1207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: 2025-JUN-1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion crawl4ai/async_crawler_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,26 @@ async def get_delayed_content(delay: float = 5.0) -> str:
)

except Exception as e:
raise e
# Handle exceptions and return error responsen in case if stream is enabled
# raising the error will cause streaming to stop instead of continuing with upcoming pages during the crawl
if config.stream:
self.logger.error(
message=f"Error during crawl: {str(e)}",
tag="ERROR",
)
return AsyncCrawlResponse(
html=str(e),
response_headers=response_headers,
status_code=500,
network_requests=captured_requests if config.capture_network_requests else None,
console_messages=captured_console if config.capture_console_messages else None,
)
else:
self.logger.error(
message=f"Error during crawl: {str(e)}",
tag="ERROR",
)
raise e

finally:
# If no session_id is given we should close the page
Expand Down