MCPcopy Create free account
hub / github.com/comuline/api / constructResponse

Function constructResponse

src/utils/response.ts:6–21  ·  view source on GitHub ↗
(
  schema: T,
  data: z.infer<T>,
)

Source from the content-addressed store, hash-verified

4import { z } from "zod"
5
6export const constructResponse = <T extends z.ZodType>(
7 schema: T,
8 data: z.infer<T>,
9): z.infer<T> => {
10 const result = schema.safeParse(data)
11
12 if (!result.success) {
13 console.log(result.error.issues)
14 throw new HTTPException(417, {
15 message: "Failed to construct a response",
16 cause: result.error.issues,
17 })
18 }
19
20 return result.data
21}
22
23interface BaseResponseSchema {
24 status: number

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected