feat(client): safe client - #751
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Co-authored-by: unnoq <64189902+unnoq@users.noreply.github.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/react
@orpc/react-query
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This PR implements the
createSafeClientfeature requested in #703, which provides automatic safe error handling for oRPC client calls without requiring manual wrapping.Problem
Previously, users had to manually wrap each client call with the
safefunction:This became repetitive when you wanted all calls to use safe error handling.
Solution
Added
createSafeClientfunction that wraps an entire client to automatically apply safe error handling:Implementation Details
SafeClient<T>type that transforms client methods to returnPromise<SafeResult<...>>instead ofClientPromiseResult<...>Features
✅ Automatic error handling - All procedure calls return safe results
✅ Nested procedure support - Works with
safeClient.user.profile.get()✅ Client options - Supports signals, context, and other options
✅ Type safety - Full TypeScript support with proper inference
✅ Destructuring - Both
{ error, data }and[error, data]stylesExamples
Basic Usage
Error Handling
Nested Procedures
Testing
Fixes #703.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.