feat(launch): friendly GitHub-limit message on Generate; document the score formula

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shay
2026-11-30 06:12:22 -08:00
co-authored by Claude Opus 5.5
parent b737a0171e
commit d907815f19
7 changed files with 78 additions and 1 deletions
+7
View File
@@ -350,6 +350,13 @@ export default function App() {
setGenerateError(body.status === 'not_found' ? 'User not found' : 'Not enrolled')
return
}
if (r.status === 503) {
const body = await r.json().catch(() => ({} as { error?: string }))
if (body.error === 'github_rate_limited') {
setGenerateError("GitHub's API limit is reached for now. Your card builds automatically once it resets (within the hour), and you can paste the embed now.")
return
}
}
if (!r.ok) {
setGenerateError(`Generate failed (HTTP ${r.status})`)
return
@@ -540,6 +540,16 @@ export function WorkshopScreen({
/>
</div>
)}
{w.id === 'grade' && (
<a
href="https://github.com/ShayManor/github-readme-stats#how-the-score-works"
target="_blank"
rel="noopener noreferrer"
className="text-[10px] text-gray-500 underline"
>
How the score works
</a>
)}
{w.id === 'impact' && (
<div>
+8 -1
View File
@@ -1135,7 +1135,14 @@ def generate(username: str):
widgets = worker.render_widgets_now(username)
except LookupError:
return jsonify({"error": "not_enrolled"}), 404
except Exception:
except Exception as e:
# The fetcher answers 503 when GitHub's quota is spent; the card
# still builds on its own once it resets, so say that, not 502.
if getattr(getattr(e, "response", None), "status_code", None) == 503:
resp = jsonify({"error": "github_rate_limited"})
resp.status_code = 503
resp.headers["Retry-After"] = "600"
return resp
log.exception("generate failed for %s", username)
return jsonify({"error": "render_failed"}), 502
finally:
+15
View File
@@ -316,6 +316,21 @@ def test_generate_endpoint_renders_and_stores_svg(client):
assert b"<svg>r</svg>" in r2.data
def test_generate_rate_limited_returns_503(client):
"""A spent GitHub quota surfaces as 503 github_rate_limited, not 502."""
import requests
dbmod.enroll("alice", {"theme": "dark"})
with client.session_transaction() as s:
s["gh_login"] = "alice"
resp = requests.Response()
resp.status_code = 503
err = requests.HTTPError("503 Server Error", response=resp)
with patch("src.worker.render_widgets_now", side_effect=err):
r = client.post("/api/alice/generate", headers={"Origin": "https://gh-stats.com"})
assert r.status_code == 503
assert r.get_json() == {"error": "github_rate_limited"}
def test_generate_endpoint_rejects_unenrolled(client):
"""With OAuth, unenrolled means having a session but no profile."""
with client.session_transaction() as s: