Skip to content

fix(api): return 408 for wait_for selector timeout in /crawl - #2186

Open
Battleplus wants to merge 1 commit into
unclecode:mainfrom
Battleplus:fix/2133-crawl-wait-for-timeout
Open

fix(api): return 408 for wait_for selector timeout in /crawl#2186
Battleplus wants to merge 1 commit into
unclecode:mainfrom
Battleplus:fix/2133-crawl-wait-for-timeout

Conversation

@Battleplus

Copy link
Copy Markdown

Summary

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.

This PR catches TimeoutError explicitly 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: Added except TimeoutError handler before the generic except Exception block, returning 408 instead of 500.

Test plan

  • POST /crawl with wait_for: "css:.nonexistent" → should return 408 with timeout detail
  • POST /crawl with a genuinely broken URL → should still return 500
  • POST /crawl with wait_for matching successfully → normal 200 response

Fixes #2133

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /crawl returns HTTP 500 when wait_for selector never matches (Docker 0.9.2)

1 participant