fix(api): return 408 for wait_for selector timeout in /crawl - #2186
Open
Battleplus wants to merge 1 commit into
Open
fix(api): return 408 for wait_for selector timeout in /crawl#2186Battleplus wants to merge 1 commit into
Battleplus wants to merge 1 commit into
Conversation
When crawler_config.wait_for specifies a CSS selector or JS condition that never matches the page, smart_wait() raises TimeoutError. The generic except Exception handler turned this into an opaque HTTP 500. Catch TimeoutError explicitly and return 408 Request Timeout with the original timeout message, so clients can distinguish server failures from selector-mismatch timeouts. Fixes unclecode#2133 Signed-off-by: Battleplus <3559424769@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
crawler_config.wait_forspecifies a CSS selector or JS condition that never matches the page,smart_wait()raisesTimeoutError. The genericexcept Exceptionhandler turned this into an opaque HTTP 500.This PR catches
TimeoutErrorexplicitly and returns 408 Request Timeout with the original timeout message, so clients can distinguish server failures from selector-mismatch timeouts.Changes
deploy/docker/api.py: Addedexcept TimeoutErrorhandler before the genericexcept Exceptionblock, returning 408 instead of 500.Test plan
POST /crawlwithwait_for: "css:.nonexistent"→ should return 408 with timeout detailPOST /crawlwith a genuinely broken URL → should still return 500POST /crawlwithwait_formatching successfully → normal 200 responseFixes #2133