errors.ts
procedure.ts
Why this shape
- the error has a stable oRPC code
- the status is explicit
- the data schema is typed
- the handler can yield the error directly
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Return typed Effect errors from procedures.
import { ORPCTaggedError } from "effect-orpc";
import * as z from "zod";
class PermissionDenied extends ORPCTaggedError("PermissionDenied", {
code: "FORBIDDEN",
status: 403,
message: "Permission denied",
schema: z.object({ requiredRole: z.string(), actualRole: z.string() }),
}) {}
const adminProcedure = eos
.$context<{ role: "viewer" | "admin" }>()
.errors({ PermissionDenied })
.use(function* ({ context }) {
if (context.role !== "admin") {
return yield* new PermissionDenied({
data: { requiredRole: "admin", actualRole: context.role },
});
}
});
export const deleteUser = adminProcedure.effect(function* () {
return { deleted: true };
});
Was this page helpful?