fix: surface API errors (rate limits, failures) in the app UIs - #2
Open
erhnysr wants to merge 1 commit into
Open
fix: surface API errors (rate limits, failures) in the app UIs#2erhnysr wants to merge 1 commit into
erhnysr wants to merge 1 commit into
Conversation
The Terminal, Calendar, and Notes apps called /api/agent/generate and read
`const { text } = await response.json()` without checking response.ok. On a
non-OK response (e.g. the middleware's 429 rate limit, or a 500) `text` was
undefined: Terminal/Calendar showed a generic message and Notes failed
silently, so the rate limiter's "Please slow down" message never reached users.
Check response.ok in all three, throw the server's message/error, and surface
it: Terminal in its fallback line, Calendar in its error bubble, and Notes via
a new inline error (previously it swallowed errors with no UI).
|
@erhnysr is attempting to deploy a commit to the 0xBuns Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
The Terminal, Calendar, and Notes apps each call
/api/agent/generateand immediately read the body without checking the HTTP status:When the response isn't OK,
textisundefinedand the app misbehaves:catchand show a generic "error processing your request" message.catch {}), so categorization just silently does nothing.The most visible casualty is the rate limiter:
middleware.tsreturns a helpful 429 body —{ "error": "Too many requests", "message": "Please slow down. Try again in a minute." }— but because no app checksresponse.ok, that message never reaches the user. A documented, headlined feature is effectively invisible.The fix
Check
response.okin all three apps before parsing. On a non-OK response, read the server'smessage/errorand throw it, then surface it in each app's existing error path:Agent error: <message> Falling back to direct execution.).destructivedesign token) so failures are visible.The generic strings are kept as fallbacks when no server message is present.
Verification (local)
Dev server up, then 21 rapid
POST /api/agent/generatecalls to trip the middleware:The apps now read
errorBody.messageand display "Please slow down. Try again in a minute." instead of a generic error (or, for Notes, instead of nothing). The 500 path ({ "error": "An error occurred processing your request" }) is covered by theerrorBody?.errorfallback.Also verified:
bunx tsc --noEmit— cleanbun run build— compiles successfullyBefore / after — Notes app
The Notes "AI Categorize All" action, run while the backend is returning the middleware's 429. Before, the failure is swallowed silently (no feedback); after, the server's message is surfaced inline.
After shows the banner "Categorization failed: Please slow down. Try again in a minute." — the exact
messagefrommiddleware.ts, which previously never reached the user. (Terminal and Calendar surface the same message in their existing error UI.)Scope
Three UI files. Same small
response.okguard in each; Notes additionally gets oneuseStateand a small inline error element since it had no error surface at all. No API/route/middleware changes.