Skip to content
Back to skills

Orpc Error Handling

ASecurity

Manage errors in oRPC using both traditional and type-safe strategies.

  • 8 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
developmentjavascriptjavagit

Works with

  • cli

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add ali-master/skills --skill orpc-error-handling --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Orpc Error Handling?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Orpc Error Handling
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ali-master-orpc-error-handling/badge)](https://www.skillsdirectory.com/skills/ali-master-orpc-error-handling)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: oRPC Error Handling
description: Manage errors in oRPC using both traditional and type-safe strategies.
license: MIT
metadata:
  author: Ali Torki
  homepage: https://github.com/ali-master
  version: "1.0.0"
---

# Error Handling in oRPC

oRPC offers a robust error handling system. You can throw standard JavaScript errors or use the specialized `ORPCError` class.

> The `ORPCError.data` property is sent to the client. Avoid including sensitive information.

## Normal Approach

```ts
const rateLimit = os.middleware(async ({ next }) => {
  throw new ORPCError('RATE_LIMITED', {
    message: 'You are being rate limited',
    data: { retryAfter: 60 }
  })
  return next()
})

const example = os
  .use(rateLimit)
  .handler(async ({ input }) => {
    throw new ORPCError('NOT_FOUND')
    throw new Error('Something went wrong') // → INTERNAL_SERVER_ERROR
  })
```

## Type-Safe Error Handling

```ts
import { os } from '@orpc/server'
import * as z from 'zod'

const base = os.errors({
  RATE_LIMITED: {
    data: z.object({ retryAfter: z.number() }),
  },
  UNAUTHORIZED: {},
})

const rateLimit = base.middleware(async ({ next, errors }) => {
  throw errors.RATE_LIMITED({
    message: 'You are being rate limited',
    data: { retryAfter: 60 }
  })
  return next()
})

const example = base
  .use(rateLimit)
  .errors({
    NOT_FOUND: { message: 'The resource was not found' },
  })
  .handler(async ({ input, errors }) => {
    throw errors.NOT_FOUND()
  })
```

## Combining Both Approaches

When you throw an `ORPCError` and `code`, `status`, and `data` match a defined error, oRPC treats it as if you used `errors.[code]`.

```ts
const rateLimit = base.middleware(async ({ next, errors }) => {
  // Both are equivalent:
  throw errors.RATE_LIMITED({ data: { retryAfter: 60 } })
  throw new ORPCError('RATE_LIMITED', { data: { retryAfter: 60 } })
  return next()
})
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.