Skip to content

fix: return 404 for nonexistent question with api scraper - #199

Open
vlnst wants to merge 1 commit into
httpjamesm:mainfrom
vlnst:fix-empty-question-panic
Open

vlnst wants to merge 1 commit into
httpjamesm:mainfrom
vlnst:fix-empty-question-panic

Conversation

@vlnst

@vlnst vlnst commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

With SCRAPER=api, a nonexistent or deleted question ID (e.g. /questions/2120178) panics with index out of range [0] with length 0 and returns a 500.

Cause: the API returns {"items":[]} for such questions, and getQuestionContent indexes Results[0] without checking.

Fix: return ErrQuestionNotFound when items is empty; ViewQuestion renders the error page with 404 for it.

Testing: added a unit test with a stubbed transport. Locally, /questions/2120178 returns 404 and /questions/11227809 returns 200.

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.

1 participant