Skip to content

杂项收尾:/api 未匹配返回 JSON 404、biome 升级修 CI、README 补 APP_URL、后端错误码 + 前端 i18n - #125

Merged
todosdev[bot] merged 3 commits into
mainfrom
tds/conv-01a14c64-9445-73bc-a605-a71f804c22f0
Oct 18, 2026
Merged

todosdev[bot] merged 3 commits into
mainfrom
tds/conv-01a14c64-9445-73bc-a605-a71f804c22f0

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Make every unmatched /api/* request (any method, including wrong-method hits on known routes) return a JSON 404 with a stable code, instead of falling through to the SPA.
  • Upgrade @biomejs/biome to 2.5.15 (the Renovate PR's target) and fix the newly-promoted noUnsafeOptionalChaining violations so CI passes.
  • Add stable code fields to backend error responses and map them through frontend i18n (en + zh-CN); fill the missing required vars in the README .dev.vars example; auto-run CI on tds/** pushes.

Changes

Backend (apps/worker)

  • src/index.ts: add an app.all('/api/*') catch-all returning JSON 404 (code: NOT_FOUND), give the error handler code: INTERNAL_SERVER_ERROR, and export app for tests.
  • src/lib/errors.ts (new): apiError(c, status, code, error) helper so every error response carries a machine-readable code alongside the original error message.
  • src/routes/auth.ts / src/routes/links.ts: attach code to all error responses across login, register, 2FA, change-password and link create/edit — plus verify-email, forgot/reset-password, refresh and passkey registration.
  • src/routes/admin.ts: fix noUnsafeOptionalChaining with a defensive (… | undefined)?.n ?? 0 (matches the existing links.ts idiom).
  • test/routing.test.ts (new): asserts JSON 404 for unknown and wrong-method /api/*, /api/health still 200, OPTIONS preflight still CORS 204, and error-code assertions for register/login.

Frontend (apps/web)

  • src/api/client.ts: propagate the response code through ApiRequestError.
  • src/lib/apiErrorCodes.ts (new) + apiErrorCodes.test.ts: code → i18n key map, cross-checked to resolve in both locales.
  • src/lib/toast.ts: resolveApiError localizes known codes and falls back to the original message otherwise.
  • src/i18n/locales/{en,zh-CN}.ts: new errors.* namespace (30+ keys).
  • All 30 toastApiError call sites now pass t.

Build / CI / docs

  • biome.json $schema → 2.5.15; package.json + pnpm-lock.yaml → biome 2.5.15 (no other dependency changes).
  • .github/workflows/ci.yml: push branches [main, 'tds/**'] so platform branch pushes run CI.
  • .github/workflows/deploy.yml: assert workflow_run.head_branch == 'main' (defense-in-depth so non-main CI can never deploy).
  • .github/workflows/tag.yml: pin the pre-tag CI lookup to branch: 'main'.
  • README.md / README.zh-CN.md: add APP_URL/APP_NAME/RP_ID/APP_ORIGIN to the .dev.vars example (APP_ORIGIN points at the Vite origin http://localhost:5173 so passkeys verify against the page origin).

Testing

  • pnpm install --frozen-lockfile, pnpm check, pnpm typecheck, pnpm build, pnpm test (worker 34 + web 28), shellcheck .github/scripts/*.sh, deploy-script tests (17), pnpm audit --prod --audit-level=high, and actionlint .github/workflows/*.yml all pass.
  • Manual (local wrangler dev + curl): duplicate-email register returns 409 {"error":"Email or username already taken","code":"EMAIL_OR_USERNAME_TAKEN"}; GET /api/does-not-exist and GET /api/auth/2fa/totp/setup return JSON 404; /login still serves the SPA.

Todos added 3 commits October 18, 2026 08:43
- Unmatched /api/* now returns a JSON 404 with a stable code instead of the
  SPA fallback (covers wrong-method hits on known routes too); added tests.
- Upgrade @biomejs/biome to 2.5.15; fix the new noUnsafeOptionalChaining rule
  in admin stats. No mass reformatting.
- Add APP_URL/APP_NAME/RP_ID/APP_ORIGIN to the .dev.vars example in both READMEs.
- Add stable error codes to auth/link responses; the frontend maps known codes
  through i18n (en + zh-CN) and falls back to the original message otherwise.

Checkpoint: xRCMbetOksxXJ9bM_fzBA
…ing tests

- Add stable error codes to verify-email, forgot/reset-password, refresh and
  passkey-registration responses, and map the missing 2FA/link codes through
  i18n (en + zh-CN).
- Point the README .dev.vars APP_ORIGIN at the Vite origin (:5173) so passkeys
  verify against the page origin.
- Add routing tests asserting /api/health still 200 and OPTIONS preflight still
  returns CORS 204.

Checkpoint: c0Po49GriX6RBspR83CqL
- Add 'tds/**' to ci.yml push branches so platform conversation-branch pushes
  auto-run CI; pull_request and workflow_dispatch are unchanged.
- Assert workflow_run.head_branch == 'main' in deploy.yml so a non-main CI run
  can never trigger the production deploy.
- Pin tag.yml's CI lookup to branch: 'main' so a tds/** push run at the same
  commit cannot satisfy the pre-tag check.

Checkpoint: RJ2gyK0wguvPmlXIIjvtw
@todosdev
todosdev Bot merged commit 29910cc into main Oct 18, 2026
4 checks passed
@mapxn
mapxn deleted the tds/conv-01a14c64-9445-73bc-a605-a71f804c22f0 branch October 18, 2026 08:56
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.

0 participants