MCPcopy Create free account
hub / github.com/middleapi/orpc / createORPCErrorConstructorMap

Function createORPCErrorConstructorMap

packages/server/src/error.ts:20–48  ·  view source on GitHub ↗
(errors: T)

Source from the content-addressed store, hash-verified

18}
19
20export function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T> {
21 /**
22 * Must use proxy to make sure any arbitrary access can be handled.
23 */
24 const proxy = new Proxy(errors, {
25 get(target, code) {
26 if (typeof code !== 'string') {
27 return Reflect.get(target, code)
28 }
29
30 const item: ORPCErrorConstructorMapItem<string, unknown> = (...rest) => {
31 const options = resolveMaybeOptionalOptions(rest)
32 const config = errors[code]
33
34 return new ORPCError(code, {
35 defined: Boolean(config),
36 status: config?.status,
37 message: options.message ?? config?.message,
38 data: options.data,
39 cause: options.cause,
40 })
41 }
42
43 return item
44 },
45 })
46
47 return proxy as any
48}

Callers 2

error.test.tsFile · 0.90
createProcedureClientFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected