feat(api): distinguish between not enrolled and not found user statuses

This commit is contained in:
shay
2026-05-03 20:38:21 -04:00
parent 954f259b8f
commit 50dd73a0de
3 changed files with 17 additions and 2 deletions
+9 -1
View File
@@ -152,11 +152,19 @@ export default function App() {
setFetchDone(true) setFetchDone(true)
return 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') setFetchError('User not found')
setFetchDone(true) setFetchDone(true)
return 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') { if (r.status === 429 || status === 'rate_limited') {
setFetchError('Enrollment limit reached — try again tomorrow') setFetchError('Enrollment limit reached — try again tomorrow')
setFetchDone(true) setFetchDone(true)
+5 -1
View File
@@ -559,7 +559,11 @@ def get_user_data(username: str):
return jsonify({"error": "invalid_username"}), 400 return jsonify({"error": "invalid_username"}), 400
settings_row = db.get_settings(username) settings_row = db.get_settings(username)
if settings_row is None: 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) db.touch_last_requested(username)
+3
View File
@@ -293,6 +293,9 @@ def test_refresh_without_session_is_401(client):
def test_data_unknown_user_returns_404(client): def test_data_unknown_user_returns_404(client):
r = client.get("/api/testuser/data") r = client.get("/api/testuser/data")
assert r.status_code == 404 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): def test_enroll_endpoint_is_gone(client):