mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(api): distinguish between not enrolled and not found user statuses
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user