fix(docker): preserve single-url crawl failure details - #2117
Conversation
|
CI note: the code-related posture-gate and security-offline checks both pass. The only failing job is the Discord notification workflow; its log shows an empty DISCORD_WEBHOOK and exits before exercising this change. This is repository/fork-secret configuration rather than a patch failure. |
|
Nice work.
if all(not result["success"] for result in results["results"]):
raise HTTPException(500, f"Crawl request failed: {results['results'][0]['error_message']}")For a single-URL request "all failed" is just "it failed", so the detail gets logged and dropped by the same 500 branch. Stock That's the same body the issue reports for The detail is already interpolated here, so switching that |
|
Thanks for the concrete reproduction. You're right: the all-results-failed branch in /crawl also raises 500, so the issue's statement that /crawl is unaffected is too broad. This PR is scoped to the two single-URL handlers from #2116, and I don't want to expand it without maintainer direction. I'm happy to include that adjacent branch here if the maintainers prefer, or it can be tracked separately. |
|
That makes sense. |
|
@nightcityblade One problem with the tests. Take a look at Also worth mentioning in the description that |
|
Thanks — addressed in I also updated the PR description to call out the 500-to-502 behavior change explicitly. The focused endpoint and exception-handler suite passes (5 tests). |
|
Tests look good now — thanks. Covering both endpoints and asserting the detail body is exactly right. @bong-u on the Merging this. |
Summary
Fixes #2116
Treat unsuccessful crawls from the single-URL
/mdand/llm/{url}handlers as upstream failures (502 Bad Gateway) so the existing exception handler preserveserror_messageinstead of replacing it with an opaque internal-server-error response. The LLM handler now also preserves deliberateHTTPExceptionstatuses. This changes those two failure responses from HTTP 500 to HTTP 502.List of files changed and why
deploy/docker/api.py- centralize unsuccessful crawl handling and return a detail-preserving 502 from both single-URL handlers.deploy/docker/tests/test_api_crawl_failures.py- verify the helper mapping and exercise authenticated/mdand/llm/{url}requests through the real FastAPI app, with a mocked failing crawler.How Has This Been Tested?
/tmp/crawl4ai-followup-venv/bin/python -m pytest deploy/docker/tests/test_api_crawl_failures.py deploy/docker/tests/test_security_headers_xss.py::TestErrorSanitization -q— 5 passed, 4 existing warnings./tmp/crawl4ai-followup-venv/bin/ruff check --isolated --select E9,F63,F7,F82 deploy/docker/api.py deploy/docker/tests/test_api_crawl_failures.py— passed./tmp/crawl4ai-followup-venv/bin/python -m compileall -q deploy/docker/api.py deploy/docker/tests/test_api_crawl_failures.py— passed.git diff --check— passed.Checklist: