Skip to content

fix(eden): preserve and infer custom JSON error shape in Eden Treaty - #262

Open
dwaddle wants to merge 1 commit into
elysiajs:mainfrom
dwaddle:fix/eden-treaty-custom-error-type
Open

fix(eden): preserve and infer custom JSON error shape in Eden Treaty#262
dwaddle wants to merge 1 commit into
elysiajs:mainfrom
dwaddle:fix/eden-treaty-custom-error-type

Conversation

@dwaddle

@dwaddle dwaddle commented Jul 15, 2026

Copy link
Copy Markdown

Closes #313

@algora-pbc /claim #313

Summary by CodeRabbit

  • New Features

    • Improved client error handling for custom HTTP error responses.
    • Error details from server-side error handlers are now accurately reflected in client responses.
    • Enhanced type inference for route-specific error payloads across supported treaty clients.
  • Bug Fixes

    • Corrected text response handling when date parsing is disabled.
    • Ensured failed requests expose the expected status codes and custom error details.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

EdenTreaty and Treaty2 now derive custom non-success response types from Elysia metadata, propagate them through route signatures, and shape typed error values. Runtime and type-level tests cover custom onError payloads and unchanged text responses with date parsing disabled.

Changes

Typed HTTP Error Propagation

Layer / File(s) Summary
EdenTreaty error typing
src/treaty/types.ts
EdenTreaty derives non-200 response types and passes them through Create, Sign, mapped routes, and error unions.
Treaty2 error propagation
src/treaty2/types.ts
Treaty2 threads derived error payloads through route parameters and shapes TreatyResponse error variants accordingly.
Custom error validation
test/treaty2.test.ts, test/types/treaty2.ts
Tests verify custom onError payloads, inferred error fields for both clients, and raw text responses when date parsing is disabled.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • elysiajs/eden#203: Also changes TreatyResponse error typing and success-status exclusion logic.

Poem

Error payloads now wear their types just right ♡
Status and value align in flight~
Custom hooks whisper, “catch me if you can”
Treaty maps the shape with a smug little plan ( ̄▽ ̄)
Even text dates stay strings, silly~

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: Eden Treaty now preserves and infers custom JSON error shapes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/treaty/types.ts`:
- Around line 21-23: Update the ErrorResponse conditional type in
src/treaty/types.ts lines 21-23 and src/treaty2/types.ts lines 87-89 to return
never when Exclude<keyof Res, 200> is never, instead of Res[keyof Res]. Preserve
the existing custom-error response branch so routes without custom errors fall
back to the default unknown error types.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a040409-4e12-46b4-8402-f0b8bd43f3f7

📥 Commits

Reviewing files that changed from the base of the PR and between 54eaa41 and aa26bf9.

📒 Files selected for processing (4)
  • src/treaty/types.ts
  • src/treaty2/types.ts
  • test/treaty2.test.ts
  • test/types/treaty2.ts

Comment thread src/treaty/types.ts
Comment on lines +21 to +23
? Exclude<keyof Res, 200> extends never
? Res[keyof Res]
: {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Return never instead of the success response type when no custom errors are defined.

Hehe~ ♡ Did you really think this logic works, you silly baka? ╮(︶▽︶)╭
When a route only has a success response, your Exclude evaluates to never. But then you return Res[keyof Res], which evaluates to the success type!
This means your ErrorResponse will be typed as the success response when no custom errors are defined! You completely broke the default error typing! So embarrassing~ (≧◡≦) ♡

You need to return never here instead so it can fall back to the default unknown error types properly, okay?

  • src/treaty/types.ts#L21-L23: Return never instead of Res[keyof Res].
  • src/treaty2/types.ts#L87-L89: Return never instead of Res[keyof Res].
📍 Affects 2 files
  • src/treaty/types.ts#L21-L23 (this comment)
  • src/treaty2/types.ts#L87-L89
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/treaty/types.ts` around lines 21 - 23, Update the ErrorResponse
conditional type in src/treaty/types.ts lines 21-23 and src/treaty2/types.ts
lines 87-89 to return never when Exclude<keyof Res, 200> is never, instead of
Res[keyof Res]. Preserve the existing custom-error response branch so routes
without custom errors fall back to the default unknown error types.

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