From 50dd73a0deae489c7c1ee9c2a71a70a7c9455c99 Mon Sep 17 00:00:00 2001 From: shay Date: Sun, 3 May 2026 20:38:21 -0400 Subject: [PATCH] feat(api): distinguish between not enrolled and not found user statuses --- generator/frontend/src/App.tsx | 10 +++++++++- generator/src/api.py | 6 +++++- generator/tests/test_api.py | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/generator/frontend/src/App.tsx b/generator/frontend/src/App.tsx index f3486ac..01dfad3 100644 --- a/generator/frontend/src/App.tsx +++ b/generator/frontend/src/App.tsx @@ -152,11 +152,19 @@ export default function App() { setFetchDone(true) return } - if (r.status === 404 || status === 'not_found') { + if (status === 'not_found') { + // Fetcher confirmed the user doesn't exist on GitHub. setFetchError('User not found') setFetchDone(true) return } + if (r.status === 404) { + // 404 without status==='not_found' means the user simply isn't + // enrolled yet (no settings row). Keep the demo data on screen + // and stop polling — no error to display. + setFetchDone(true) + return + } if (r.status === 429 || status === 'rate_limited') { setFetchError('Enrollment limit reached — try again tomorrow') setFetchDone(true) diff --git a/generator/src/api.py b/generator/src/api.py index 6fe6493..b5b58e4 100644 --- a/generator/src/api.py +++ b/generator/src/api.py @@ -559,7 +559,11 @@ def get_user_data(username: str): return jsonify({"error": "invalid_username"}), 400 settings_row = db.get_settings(username) if settings_row is None: - return jsonify({"status": "not_found"}), 404 + # The user has never been enrolled. We don't know yet whether they + # exist on GitHub — only the fetcher can confirm that. Use a + # distinct status so the frontend doesn't surface a misleading + # "User not found" error for a user who simply hasn't signed in. + return jsonify({"status": "not_enrolled"}), 404 db.touch_last_requested(username) diff --git a/generator/tests/test_api.py b/generator/tests/test_api.py index ccb1735..05934ba 100644 --- a/generator/tests/test_api.py +++ b/generator/tests/test_api.py @@ -293,6 +293,9 @@ def test_refresh_without_session_is_401(client): def test_data_unknown_user_returns_404(client): r = client.get("/api/testuser/data") assert r.status_code == 404 + # Unknown-but-not-enrolled is distinct from confirmed-not-on-GitHub so + # the frontend can avoid a misleading "User not found" message. + assert r.get_json()["status"] == "not_enrolled" def test_enroll_endpoint_is_gone(client):