MCPcopy Create free account
hub / github.com/ShaanCoding/makeread.me / validateRequest

Function validateRequest

backend/src/common/utils/httpHandlers.ts:11–24  ·  view source on GitHub ↗
(schema: ZodSchema)

Source from the content-addressed store, hash-verified

9}
10
11export const validateRequest = (schema: ZodSchema) => (req: Request, res: Response, next: NextFunction) => {
12 try {
13 schema.parse({
14 body: req.body,
15 query: req.query,
16 params: req.params,
17 })
18 next()
19 } catch (err) {
20 const errorMessage = `Invalid input: ${(err as ZodError).errors.map((e) => e.message).join(', ')}`
21 const statusCode = StatusCodes.BAD_REQUEST
22 res.status(statusCode).send(new ServiceResponse<null>(ResponseStatus.Failed, errorMessage, null, statusCode))
23 }
24}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected