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

Function validateORPCError

packages/contract/src/error.ts:58–83  ·  view source on GitHub ↗
(map: ErrorMap, error: ORPCError<any, any>)

Source from the content-addressed store, hash-verified

56export type ErrorFromErrorMap<TErrorMap extends ErrorMap> = ORPCErrorFromErrorMap<TErrorMap> | ThrowableError
57
58export async function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>> {
59 const { code, status, message, data, cause, defined } = error
60 const config = map?.[error.code]
61
62 if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
63 return defined
64 ? new ORPCError(code, { defined: false, status, message, data, cause })
65 : error
66 }
67
68 if (!config.data) {
69 return defined
70 ? error
71 : new ORPCError(code, { defined: true, status, message, data, cause })
72 }
73
74 const validated = await config.data['~standard'].validate(error.data)
75
76 if (validated.issues) {
77 return defined
78 ? new ORPCError(code, { defined: false, status, message, data, cause })
79 : error
80 }
81
82 return new ORPCError(code, { defined: true, status, message, data: validated.value, cause })
83}

Callers 3

error.test.tsFile · 0.90
initMethod · 0.90
validateErrorFunction · 0.90

Calls 1

fallbackORPCErrorStatusFunction · 0.90

Tested by

no test coverage detected