fix(act-http): tRPC actor deny maps to UNAUTHORIZED (401), not 500 (ACT-1286) - #1291
Merged
Conversation
…00 (#1286) The trpc() generator resolved the actor inside the mutation's main try, so a "throw to deny" from the extractor (a plain Error) fell through to_trpc_error → toApiError(500) → INTERNAL_SERVER_ERROR, while Hono's `authenticated` middleware returns 401. The auto-generated-API guide explicitly promises the throw-to-deny semantics are identical (both UNAUTHORIZED). Resolve the actor in its own try that maps any extractor throw to TRPCError({code: "UNAUTHORIZED"}) (preserving the message), distinct from a framework error inside app.do. Adds a red-first test (Error + non-Error deny → 401) matching Hono. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
🎉 This PR is included in version @rotorsoft/act-http-v1.8.8 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version @rotorsoft/act-tck-v1.27.13 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Summary
Fixes #1286. The
trpc()generator resolvedoptions.actor()inside the mutation's main try, so a "throw to deny" from the extractor (a plainError) fell throughto_trpc_error→toApiError(500) →INTERNAL_SERVER_ERROR. Hono'sauthenticatedmiddleware returns 401UNAUTHORIZEDfor the same deny. The guide explicitly promises the throw-to-deny semantics are identical (auto-generated-api.md:189,249,348) — unlike #1280 this divergence is promised NOT to exist.Fix
Resolve the actor in its own
trythat maps any extractor throw toTRPCError({ code: "UNAUTHORIZED" })(preserving the message), distinct from a framework error insideapp.do(which the main try still maps viato_trpc_error).Proof (red-first)
New tests over the generated router:
Plus a non-Error deny → 401 (branch coverage). The doc already described this behavior; the code now matches it, so no doc change.
Scope
Internal to the generator; the exported
trpc(...)signature is unchanged. 100% coverage.Gates
Typecheck ✅ · tests ✅ · 100% coverage ✅ · lint ✅ · build ✅.
rfc-gate: exempt — no new public surface. The snapshot delta is the internal mutation-handler source text in
trpc/index.ts; no export added or changed.Closes #1286
🤖 Generated with Claude Code