Skip to content

Conversation

bogeychan
Copy link
Contributor

@bogeychan bogeychan commented Aug 7, 2025

Closes #201

Summary by CodeRabbit

  • New Features

    • Treats all HTTP 2xx status codes as success responses (not only 200), broadening success handling across the client.
  • Tests

    • Added type-level tests covering responses with various status codes (below 200, 200–299, 300+) to verify correct data vs. error inference.

Copy link

coderabbitai bot commented Aug 7, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds numeric range utility types and updates TreatyResponse to treat any 2xx status (200–299) as success; adds tests validating type inference for responses with various status codes.

Changes

Cohort / File(s) Change Summary
Type Utilities & TreatyResponse Update
src/treaty2/types.ts
Added Enumerate, IntegerRange, SuccessCodeRange, IsSuccessCode. Replaced literal 200 usages in TreatyResponse with range-based logic (Extract<keyof Res, SuccessCodeRange> / SuccessCodeRange) so 2xx codes are treated as success.
Type Inference Tests
test/types/treaty2.ts
Added tests that instantiate Elysia apps returning status(code, value) for codes 199, 200, 201, 299, 300 and assert treaty client type inference for data vs error across the 2xx boundary.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Treaty
    participant ElysiaApp

    Client->>Treaty: request (GET)
    Treaty->>ElysiaApp: forward request
    ElysiaApp-->>Treaty: respond with status X and payload
    Treaty-->>Client: mapped response
    Note right of Treaty: success if 200–299 → populate `data`<br>otherwise → populate `error`
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

"I hop through types with nimble paws,
From two-oh-oh to two-nine-nine applause.
Ranges sewn and tests that play,
Now success is wide — hip hip hooray! 🐇✨"

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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 0e782a7 and 29baec4.

📒 Files selected for processing (2)
  • src/treaty2/types.ts (3 hunks)
  • test/types/treaty2.ts (2 hunks)

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 and usage tips.

Copy link

@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: 0

🧹 Nitpick comments (1)
src/treaty2/types.ts (1)

41-42: Consider TypeScript recursion depth limits

The Enumerate type uses recursive type instantiation which has a default depth limit of 1000 in TypeScript. While generating 100 values (200-299) is well within limits, this implementation could fail for larger ranges.

For future extensibility, consider documenting this limitation or implementing a more efficient approach for larger ranges if needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b0519b and 0e782a7.

📒 Files selected for processing (2)
  • src/treaty2/types.ts (3 hunks)
  • test/types/treaty2.ts (2 hunks)
🔇 Additional comments (3)
src/treaty2/types.ts (2)

44-47: Well-implemented HTTP success status range types

The IntegerRange and SuccessCodeRange types correctly model the HTTP 2xx success status range (200-299). The IsSuccessCode helper provides a clean way to check membership in this range.


168-200: Correct generalization of HTTP success status handling

The TreatyResponse type now properly handles all 2xx status codes as success responses, which aligns with HTTP specification standards. The use of Extract and Exclude with SuccessCodeRange cleanly separates success and error cases.

test/types/treaty2.ts (1)

1068-1131: Comprehensive test coverage for HTTP status code ranges

The new test cases thoroughly verify the type inference behavior across the boundary conditions:

  • Below 2xx range (199)
  • Start of 2xx range (200)
  • Middle of 2xx range (201)
  • End of 2xx range (299)
  • Above 2xx range (300)

The assertions correctly validate that 2xx codes result in typed data and unknown errors, while non-2xx codes result in unknown data and typed errors.

@DaxServer
Copy link

Looks like two PRs are open solving the same #204

@SaltyAom SaltyAom merged commit a718119 into elysiajs:main Oct 11, 2025
1 of 2 checks passed
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.

Error codes returned in middleware are not inferred by Eden Treaty

3 participants