Skip to content

[BUG] GitHub GraphQL errors aren't handled — /github/activity, /streak, /heatmap 500 on a bad/expired token #64

Description

@vedant7007

Describe the Bug

The three GraphQL methods in backend/app/services/github_service.py (get_activity ~line 46, get_heatmap ~line 107, and get_streak, which calls get_activity) do data = response.json() and then index straight into data["data"]["user"]["contributionsCollection"] with no status or error check. So a "Bad credentials" body (no data key → KeyError), a rate-limit error, or {"data": {"user": null}} for an unknown/renamed user (→ TypeError: NoneType not subscriptable) makes the endpoint 500 with a raw traceback. There's also no raise_for_status() or timeout on those posts. This is a separate path from #61, which is the REST get_language_breakdown.

Where

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

Steps to Reproduce

  1. Connect a GitHub account, then revoke/expire the token (or hit a GitHub rate-limit)
  2. Load the dashboard, which calls /github/activity, /github/streak, /github/heatmap
  3. Endpoint returns a 500 instead of a graceful message

Expected Behavior

On a bad/expired token or rate-limit, these should return a clean error (e.g. HTTPException 401/429 with a "reconnect your GitHub" message), not a 500 with a traceback.

Screenshots / Terminal Output

KeyError: 'data' (bad credentials) or TypeError: 'NoneType' object is not subscriptable (when data.data.user is null), raised from github_service.py.

Environment

  • OS: any (reproducible cross-platform; observed on Windows 11)
  • Browser (if frontend): n/a — backend
  • CLI version (if CLI): n/a
  • Commit: f3dd729

Additional Context

Suggested fix: check response.status_code, look for a top-level errors key, and guard data.get("data", {}).get("user") being None; raise a clear HTTPException (surfacing X-RateLimit-Remaining when present). 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