Skip to content

Give curl the same recovery hints the CLI prints - #88

Merged
david-sling merged 1 commit into
mainfrom
api-error-hints
Sep 28, 2026
Merged

david-sling merged 1 commit into
mainfrom
api-error-hints

Conversation

@david-sling

Copy link
Copy Markdown
Owner

Refs #75. This is the server half of the CLI error work in 68c97eb.

The CLI prints the server's message and hint, then adds its own meaning through exit codes: 5 on a 401 or 410 means stop. An agent using curl only sees the response body, so the body now carries that meaning too.

  • 410: the hint says this is final. No retry or token will bring the channel back.
  • 401: the hint names the token the endpoint takes and where it comes from, and says tokens are never reissued. If the token is the word null or undefined (what a failed join leaves in a token file), the hint says so.
  • 500 and the fixed-window 429: both now have hints saying whether a retry is safe.
  • Unknown path under /api: now 404 not_found listing every endpoint and linking the curl guide. Before, it returned the site's HTML 404 page.
  • Wrong method: now 405 method_not_allowed with an Allow header. Before, Next returned an empty 405. Each route also exports OPTIONS, so Next's generated Allow header doesn't list the refusal handlers as allowed.

The endpoint list lives in one place, lib/endpoints.ts, and both the 404 and the 405 answers read from it.

Checks

  • New tests in tests/api-errors.test.ts. The typecheck, ESLint, the app suite (615 tests) and the CLI suite (148 tests) all pass.
  • Ran every case above with curl against a local next dev, including the catch-all's routing and the HEAD/OPTIONS behaviour.

Merge order

Merge this before the Prettier PR. Both touch lib/http.ts, lib/auth.ts and the route files. Rebasing the reformat onto this and re-running npm run format is trivial; the other order is not.

🤖 Generated with Claude Code

Refs #75.

The CLI relays the server's message and hint, and adds its own meaning on
top: exit 5 for a 401 or 410 says stop. An agent on curl only has the body,
so the body now carries that meaning.

- 410 says it is final: no retry or token brings the channel back.
- 401 names the token the endpoint takes and where it comes from, and says
  tokens are never reissued. A token that is the word "null" or "undefined"
  is called out as what a failed join leaves in a token file.
- 500 says the fault is the instance's, and that a post is safe to retry with
  the same client_id. The fixed-window 429 says every request before
  Retry-After is refused too.
- An unknown path under /api answers not_found with every endpoint and the
  curl guide, where it returned the site's HTML 404 page.
- A method a route does not take answers method_not_allowed with an Allow
  header, where Next returned an empty 405. Each route exports OPTIONS too,
  so the generated Allow does not list the refusals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
wave Ready Ready Preview Sep 28, 2026 7:30pm UTC

@david-sling
david-sling merged commit ca84dd1 into main Sep 28, 2026
5 of 6 checks passed
@david-sling
david-sling deleted the api-error-hints branch September 28, 2026 19:30

This branch was successfully deployed

1 active deployment
Preview — 56d99409 Deployed Sep 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant