Skip to content

feat: add precondition required response code#6954

Merged
KATT merged 8 commits intotrpc:mainfrom
y-nk:julien/precondition-required
Sep 23, 2025
Merged

feat: add precondition required response code#6954
KATT merged 8 commits intotrpc:mainfrom
y-nk:julien/precondition-required

Conversation

@y-nk
Copy link
Copy Markdown
Contributor

@y-nk y-nk commented Sep 22, 2025

Closes #

🎯 Changes

What changes are made in this PR? Is it a feature or a bug fix?

#6885

adds missing 428 http error which i require.

✅ Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

Summary by CodeRabbit

  • New Features

    • Added PRECONDITION_REQUIRED as a new error type with a numeric RPC code and HTTP 428 mapping so clients can receive and interpret this condition via both RPC and HTTP.
  • Documentation

    • Docs updated to describe the PRECONDITION_REQUIRED error, its HTTP 428 mapping, example usage, and guidance for handling this condition.

@y-nk y-nk requested a review from a team as a code owner September 22, 2025 03:28
@vercel
Copy link
Copy Markdown

vercel bot commented Sep 22, 2025

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

Project Deployment Preview Comments Updated (UTC)
www Ready Ready Preview Comment Sep 23, 2025 5:30am

@vercel
Copy link
Copy Markdown

vercel bot commented Sep 22, 2025

@y-nk is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

Nick-Lucas
Nick-Lucas previously approved these changes Sep 22, 2025
Copy link
Copy Markdown
Member

@KATT KATT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails typecheck

@KATT
Copy link
Copy Markdown
Member

KATT commented Sep 22, 2025

Also I think this should be updated in some doc

@y-nk
Copy link
Copy Markdown
Contributor Author

y-nk commented Sep 23, 2025

@KATT while i'm at it, would you want me to add the rest of the missing http codes?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

Adds a new TRPC error key PRECONDITION_REQUIRED (code -32028) and maps it to HTTP status 428 across server mappings and documentation. No API signatures or runtime control flow were changed.

Changes

Cohort / File(s) Summary
HTTP ↔ RPC status mappings
packages/server/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts
Added PRECONDITION_REQUIRED ↔ 428 entries to JSONRPC2_TO_HTTP_CODE and HTTP_CODE_TO_JSONRPC2.
RPC error codes
packages/server/src/unstable-core-do-not-import/rpc/codes.ts
Added PRECONDITION_REQUIRED: -32028 to TRPC_ERROR_CODES_BY_KEY and [-32028]: 'PRECONDITION_REQUIRED' to TRPC_ERROR_CODES_BY_NUMBER.
Documentation updates
www/docs/further/rpc.md, www/docs/server/error-handling.md
Documented new PRECONDITION_REQUIRED mapping: HTTP 428 and internal code -32028; added table entries and descriptive text.

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels

♻️ autoupdate

Suggested reviewers

  • KATT

Poem

Hop-hop, a mapping bright I bring,
PRECONDITION_REQUIRED makes the server sing.
428 at the door, -32028 in rhyme,
Little rabbit patched the code in time. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "feat: add precondition required response code" is a concise, single-sentence summary that accurately reflects the main change (adding the HTTP 428 Precondition Required code) and is relevant to the changes in the PR. It is specific enough for a teammate scanning history and avoids unnecessary noise.
Description Check ✅ Passed The PR description follows the repository template structure and includes a brief summary plus a link to the related issue, so it is mostly complete and on-topic; however the "Closes #" line is left empty and the checklist still shows documentation/tests as not added even though documentation files were modified per the changeset. The description therefore conveys the intent but needs small corrections to fully match the template and accurately reflect what was changed.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4de7d4 and ba8e168.

📒 Files selected for processing (1)
  • www/docs/server/error-handling.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • www/docs/server/error-handling.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: E2E-tests (cloudflare-workers)
  • GitHub Check: E2E-tests (.test/diagnostics-big-router)
  • GitHub Check: E2E-tests (.experimental/next-app-dir)
  • GitHub Check: E2E-tests (.test/internal-types-export)
  • GitHub Check: E2E-tests (minimal-react)
  • GitHub Check: E2E-tests (.test/ssg)
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 20.x)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 20.x)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 20.x)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 18.x)
  • GitHub Check: E2E-tests (Bun) (bun, ubuntu-latest)
  • GitHub Check: E2E-tests (Deno) (deno-deploy)
  • GitHub Check: Release using pkg.pr.new
  • GitHub Check: Test a monorepo using built declaration files
  • GitHub Check: typecheck-www
  • GitHub Check: test
  • GitHub Check: typecheck
  • GitHub Check: Lint and auto-fix

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Sep 23, 2025

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/trpc/trpc/@trpc/client@6954

@trpc/next

npm i https://pkg.pr.new/trpc/trpc/@trpc/next@6954

@trpc/react-query

npm i https://pkg.pr.new/trpc/trpc/@trpc/react-query@6954

@trpc/server

npm i https://pkg.pr.new/trpc/trpc/@trpc/server@6954

@trpc/tanstack-react-query

npm i https://pkg.pr.new/trpc/trpc/@trpc/tanstack-react-query@6954

@trpc/upgrade

npm i https://pkg.pr.new/trpc/trpc/@trpc/upgrade@6954

commit: ba8e168

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 864f40c and a214b60.

📒 Files selected for processing (2)
  • www/docs/further/rpc.md (2 hunks)
  • www/docs/server/error-handling.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,md,mdx}

📄 CodeRabbit inference engine (.cursor/rules/coding-guidelines.mdc)

Use camelCase for file names (with exceptions like TRPC/RPC/HTTP/JSON acronyms, .config.js, .d.ts, and tests)

Files:

  • www/docs/server/error-handling.md
  • www/docs/further/rpc.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test
  • GitHub Check: build
  • GitHub Check: typecheck
  • GitHub Check: Lint and auto-fix
🔇 Additional comments (2)
www/docs/further/rpc.md (2)

207-207: Mapping looks correct: PRECONDITION_REQUIRED → 428.

This aligns with HTTP 428 and complements TOO_MANY_REQUESTS (429).


258-258: JSON-RPC mapping looks correct: PRECONDITION_REQUIRED → -32028.

Consistent with the “copy last digits of HTTP 4XX” convention.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 482d554 and d4de7d4.

📒 Files selected for processing (1)
  • www/docs/server/error-handling.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,md,mdx}

📄 CodeRabbit inference engine (.cursor/rules/coding-guidelines.mdc)

Use camelCase for file names (with exceptions like TRPC/RPC/HTTP/JSON acronyms, .config.js, .d.ts, and tests)

Files:

  • www/docs/server/error-handling.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: E2E-tests (.test/ssg)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 20.x)
  • GitHub Check: E2E-tests (.test/internal-types-export)
  • GitHub Check: E2E-tests (soa)
  • GitHub Check: E2E-tests (next-prisma-todomvc)
  • GitHub Check: E2E-tests (next-prisma-starter)
  • GitHub Check: E2E-tests (express-server)
  • GitHub Check: E2E-tests (.test/diagnostics-big-router)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 20.x)
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 20.x)
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 18.x)
  • GitHub Check: Test a monorepo using built declaration files
  • GitHub Check: E2E-tests (Deno) (deno-deploy)
  • GitHub Check: Release using pkg.pr.new
  • GitHub Check: E2E-tests (Bun) (bun, ubuntu-latest)
  • GitHub Check: typecheck-www
  • GitHub Check: test
  • GitHub Check: Lint and auto-fix
🔇 Additional comments (1)
www/docs/server/error-handling.md (1)

41-41: Verify naming: METHOD_NOT_SUPPORTED vs METHOD_NOT_ALLOWED

Docs show METHOD_NOT_SUPPORTED (www/docs/server/error-handling.md:41). Confirm the codebase's TRPC error-key for HTTP 405 (TRPC_ERROR_CODES_BY_KEY and any reverse mappings) and make docs or constants consistent.

Run locally:

  • rg -n -S '\bMETHOD_NOT_SUPPORTED\b|\bMETHOD_NOT_ALLOWED\b'
  • rg -n -S 'TRPC_ERROR_CODES_BY_KEY' and inspect which key maps to 405

@KATT KATT merged commit 7f0f1e4 into trpc:main Sep 23, 2025
43 of 46 checks passed
@y-nk y-nk deleted the julien/precondition-required branch September 24, 2025 00:55
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants