Skip to content

feat(server): error on unsupported batch response types#355

Merged
dinwwwh merged 1 commit into
mainfrom
feat/server/throw-errors-on-unsupported-procedure-response
Apr 10, 2025
Merged

feat(server): error on unsupported batch response types#355
dinwwwh merged 1 commit into
mainfrom
feat/server/throw-errors-on-unsupported-procedure-response

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Apr 10, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling for batch requests so that unsupported content types (e.g., file uploads or form data) now trigger a clear 500 error with a descriptive message.
  • Tests

    • Expanded test coverage to verify the updated error responses, ensuring reliable behavior when processing unsupported batch request types.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 10, 2025 3:47am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 10, 2025

Walkthrough

This pull request introduces enhancements to the error handling of the batch processing system. A new test case in the batch handler’s test suite verifies that unsupported response types (such as Blob and FormData) return a 500 status code along with an appropriate error message. Additionally, the BatchHandlerPlugin has been updated with conditional logic in its init method to detect and handle Blob, FormData, and asynchronous iterator objects by returning a standardized error response. The modifications also include an update to the import statements to support these checks.

Changes

File(s) Change Summary
packages/.../batch.test.ts Added a test case for batch requests with unsupported body types (Blob and FormData) to ensure 500 error responses are correctly generated.
packages/.../batch.ts Enhanced the BatchHandlerPlugin by adding conditionals in the init method to detect Blob, FormData, and async iterator objects, returning a 500 error response when encountered; updated import to include isAsyncIteratorObject.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant T as Test Suite
    participant B as BatchHandlerPlugin
    T->>B: Send batch request with various body types (Blob, FormData, string)
    B->>B: Check if response.body is Blob, FormData, or async iterator
    alt Unsupported type detected
        B->>T: Return 500 status with error message
    else Supported type
        B->>T: Process and return 200 status with response
    end
Loading

Possibly related PRs

  • unnoq/orpc#220: Enhances error handling for request and response types within the BatchHandlerPlugin by refining type definitions.
  • unnoq/orpc#354: Refines the structure and validation of batch response items, providing a complementary approach to batch response error handling.

Poem

I'm a rabbit, swift on my toes,
Hopping through code where logic grows,
Blob and FormData give a quirky twist,
With 500 errors, I simply can't resist,
Jumping with joy on this testing spree!
🐰💻


📜 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 a6dec3e and 9da4710.

📒 Files selected for processing (2)
  • packages/server/src/plugins/batch.test.ts (1 hunks)
  • packages/server/src/plugins/batch.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/server/src/plugins/batch.ts (1)
packages/shared/src/iterator.ts (1)
  • isAsyncIteratorObject (1-7)
packages/server/src/plugins/batch.test.ts (2)
packages/standard-server/src/batch/request.ts (1)
  • toBatchRequest (12-38)
packages/standard-server/src/batch/response.ts (1)
  • parseBatchResponse (33-63)
🔇 Additional comments (3)
packages/server/src/plugins/batch.ts (2)

6-6: LGTM: New import addresses the new functionality

This import adds the required function to check for async iterator objects and maintains the existing value import.


98-110: Well-implemented error handling for unsupported response types

This change adds proper error handling for batch responses that contain types that can't be easily serialized in batch responses (Blob, FormData, or async iterators). The error message clearly indicates that these operations should be performed outside batch requests.

The implementation is clean and follows the existing pattern of returning a structured error response with index, status, headers, and body.

packages/server/src/plugins/batch.test.ts (1)

450-508: Comprehensive test coverage for unsupported response types

The test case thoroughly verifies the new error handling for unsupported response types in batch requests. It correctly tests:

  1. Multiple unsupported types (Blob and FormData)
  2. Appropriate error messages and status codes for unsupported types
  3. Proper handling of supported types in the same batch request

The test properly validates the expected behavior as implemented in the BatchHandlerPlugin.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 10, 2025

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@355

@orpc/client

npm i https://pkg.pr.new/@orpc/client@355

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@355

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@355

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@355

@orpc/react

npm i https://pkg.pr.new/@orpc/react@355

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@355

@orpc/server

npm i https://pkg.pr.new/@orpc/server@355

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@355

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@355

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@355

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@355

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@355

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@355

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@355

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@355

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@355

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@355

commit: 9da4710

@dinwwwh dinwwwh merged commit bb2589d into main Apr 10, 2025
8 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.

1 participant