From 9f38b903e5a3bbbe5cabfe16fffac746f95b4583 Mon Sep 17 00:00:00 2001 From: Battleplus <3559424769@qq.com> Date: Mon, 24 Aug 2026 00:51:23 +0800 Subject: [PATCH] fix(api): return 403 for anti-bot blocked results in /md and /llm endpoints Both handle_markdown_request and handle_llm_qa promoted any unsuccessful crawl into HTTP 500. Since 0.8.5, is_blocked() sets success=False with error_message 'Blocked by anti-bot protection: ', so Cloudflare- protected sites returned opaque 500 instead of a client-meaningful error. Differentiate anti-bot failures (403) from genuine server errors (500) by inspecting the error message for 'blocked' / 'anti-bot' keywords. Fixes #2116 Signed-off-by: Battleplus <3559424769@qq.com> --- deploy/docker/api.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/deploy/docker/api.py b/deploy/docker/api.py index 1756b925f..f5ea26e88 100644 --- a/deploy/docker/api.py +++ b/deploy/docker/api.py @@ -148,9 +148,11 @@ async def handle_llm_qa( crawler = await get_crawler(browser_cfg) result = await crawler.arun(url) if not result.success: + err = result.error_message or "Crawl failed" + code = status.HTTP_403_FORBIDDEN if "blocked" in err.lower() or "anti-bot" in err.lower() else status.HTTP_500_INTERNAL_SERVER_ERROR raise HTTPException( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=result.error_message + status_code=code, + detail=err ) content = result.markdown.fit_markdown or result.markdown.raw_markdown @@ -390,9 +392,11 @@ async def handle_markdown_request( ) if not result.success: + err = result.error_message or "Crawl failed" + code = status.HTTP_403_FORBIDDEN if "blocked" in err.lower() or "anti-bot" in err.lower() else status.HTTP_500_INTERNAL_SERVER_ERROR raise HTTPException( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=result.error_message + status_code=code, + detail=err ) return (result.markdown.raw_markdown