Skip to content

Conversation

bogeychan
Copy link

@bogeychan bogeychan commented Aug 7, 2025

Closes #201

Summary by CodeRabbit

  • New Features

    • Expanded support for recognizing all HTTP 2xx status codes as success responses, not just 200, improving flexibility in API response handling.
  • Tests

    • Added comprehensive tests to verify correct type inference for various HTTP status codes, ensuring accurate distinction between success and error responses.

Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

The changes introduce new TypeScript utility types for numeric range handling and update the TreatyResponse type to generalize HTTP success status code handling from a single code (200) to the full 2xx range (200–299). Corresponding type inference tests were added to verify correct behavior for various HTTP status codes.

Changes

Cohort / File(s) Change Summary
Type Utilities & TreatyResponse Update
src/treaty2/types.ts
Added utility types (Enumerate, IntegerRange, SuccessCodeRange, IsSuccessCode) for numeric ranges. Updated TreatyResponse to use SuccessCodeRange instead of hardcoded 200, generalizing success code handling.
Type Inference Tests
test/types/treaty2.ts
Added test cases to verify treaty client type inference for endpoints returning different HTTP status codes. Ensured correct typing of data and error properties for both success (2xx) and non-success codes.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Treaty
    participant ElysiaApp

    Client->>Treaty: Send GET request
    Treaty->>ElysiaApp: Forward request
    ElysiaApp-->>Treaty: Respond with status code (e.g., 199, 200, 201, 299, 300)
    Treaty-->>Client: Return response
    Note right of Treaty: Type mapping:<br>status 200-299 → data<br>otherwise → error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

In fields of code, a rabbit hops,
From 200 to 299, success never stops!
With types that range and tests that sing,
Now Treaty’s smarter in everything.
🐇✨
So here’s a cheer for status done right—
Our burrow’s code shines ever bright!

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

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
2 participants