oRPC propagates server errors to the client asDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/middleapi/orpc/llms.txt
Use this file to discover all available pages before exploring further.
ORPCError instances. Procedures can also declare typed errors using .errors({}) — these are surfaced with full type information so you can handle them precisely.
ORPCError
Every error thrown by an oRPC procedure arrives on the client as anORPCError. Use instanceof to check:
Built-in error codes
oRPC defines standard codes that map to HTTP status codes:| Code | Status |
|---|---|
BAD_REQUEST | 400 |
UNAUTHORIZED | 401 |
FORBIDDEN | 403 |
NOT_FOUND | 404 |
CONFLICT | 409 |
UNPROCESSABLE_CONTENT | 422 |
TOO_MANY_REQUESTS | 429 |
INTERNAL_SERVER_ERROR | 500 |
SERVICE_UNAVAILABLE | 503 |
isDefinedError
When a procedure declares typed errors with.errors({}), those errors have defined: true set on them. Use isDefinedError to narrow an error to the typed union:
isDefinedError(error) returns true when error instanceof ORPCError && error.defined.
safe()
Thesafe() helper wraps any ClientPromiseResult and returns a SafeResult that supports both tuple-style and object-style destructuring. It never throws.
SafeResult structure
| Case | error | data | isDefined | isSuccess |
|---|---|---|---|---|
| Success | null | output | false | true |
| Typed error | ORPCError | undefined | true | false |
| Unexpected error | error | undefined | false | false |
createSafeClient
createSafeClient(client) wraps an entire client so that every call returns a SafeResult instead of throwing. This is useful when you want a consistent error-handling pattern across your application.
Handling typed errors end-to-end
When you define typed errors on the server, they flow through to the client with full type information:The
instanceof ORPCError check works correctly even when oRPC is loaded in multiple module contexts (e.g. Next.js with optimised SSR). oRPC maintains a global registry of ORPCError constructors to make cross-context checks reliable.