Skip to content

fix: resolve 500 errors on missing keywords and unsafe 404 handler, a…#179

Open
TesfamichaelA-code wants to merge 1 commit into
c2siorg:mainfrom
TesfamichaelA-code:fix-route-edgecases-and-tests
Open

fix: resolve 500 errors on missing keywords and unsafe 404 handler, a…#179
TesfamichaelA-code wants to merge 1 commit into
c2siorg:mainfrom
TesfamichaelA-code:fix-route-edgecases-and-tests

Conversation

@TesfamichaelA-code

Copy link
Copy Markdown

…dd tests

Description

Found two bugs while reading through the backend for my GSoC application and fixed them:

  1. IndexError on missing keywords param
    If you hit /news_keywords without a ?keywords= value (or with an empty one), the code tried to access user_keywords[0] on an empty list and crashed with a 500. Now returns a 400 instead.
  2. Double crash in the 404 handler
    The 404 handler called g.news_controller.notFound() without checking if g.news_controller was actually set. On bad routes it never gets initialized, so you'd get a 500 error while trying to handle a 404. Added a hasattr() check to handle this gracefully.
  3. Fixed existing tests + added new ones
    The existing test_news and test_news_keywords tests were hitting /news and /news_keywords directly, which match the /<llm_name> catch-all route — not the actual news endpoints. Fixed those. Also added tests for the missing/empty param cases, and switched to /raw endpoints so the suite doesn't need a HuggingFace API key to run in CI.

Related Issue

No related issue — found these bugs while reading through the codebase for my GSoC 2026 application.

How Has This Been Tested?

Ran unitTest.py locally, all 5 tests pass. Also tested manually by hitting a bad URL and intentionally running without a .env file to confirm CI safety.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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