Skip to content

[BUG] Groq insights call has no error handling — /insights/weekly 500s without a key #68

Description

@vedant7007

Describe the Bug

_call_groq (backend/app/services/insights_service.py:14) does data = response.json() then returns data["choices"][0]["message"]["content"] with no status check. GROQ_API_KEY defaults to "" (configuration.py:19), so with no key configured Groq returns a 401 body (no choices) → KeyError/insights/weekly 500s. Same happens on a Groq rate-limit or model error.

Where

  • Frontend (web dashboard)
  • Backend (API)
  • CLI (clutch-cli)

Steps to Reproduce

  1. Leave GROQ_API_KEY unset (its default)
  2. Call /insights/weekly
  3. Endpoint 500s

Expected Behavior

Degrade gracefully — check the status / confirm choices exists and return {"message": "AI insight unavailable"} (or a clean HTTPException); short-circuit with a friendly message when the key isn't set.

Screenshots / Terminal Output

KeyError: 'choices' from insights_service.py when Groq returns a non-200 body.

Environment

  • OS: any
  • Browser (if frontend): n/a — backend
  • CLI version (if CLI): n/a
  • Commit: f3dd729

Additional Context

The frontend does swallow this (DashboardPage.tsx:55), but the backend still logs 500s and returns nothing useful. Happy to take it if you assign me.

Contributing as part of Elite Coders Summer of Code (ECSoC 2026).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions