File
Blob: worker/src/server/rpc.ts
| 1 | export class OperationError extends Error { |
| 2 | readonly status: number; |
| 3 | constructor(status: number, message: string) { |
| 4 | super(message); |
| 5 | this.status = status; |
| 6 | } |
| 7 | } |
| 8 | export function demand(value: unknown, status: number, message: string): asserts value { |
| 9 | if (!value) throw new OperationError(status, message); |
| 10 | } |
| 11 | |
| 12 | /** Expected failures cross the RPC boundary as data, preserving status codes. */ |
| 13 | export type RpcResult<T> = { ok: true; value: T } | { ok: false; status: number; error: string }; |