( schema: T, data: z.infer<T>, )
| 4 | import { z } from "zod" |
| 5 | |
| 6 | export 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 | |
| 23 | interface BaseResponseSchema { |
| 24 | status: number |
nothing calls this directly
no outgoing calls
no test coverage detected