]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/utils.ts
77a1a0d4bfb4c5a7ded8dec4ccdaecd890fc85a9
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / utils.ts
1 import { validationResult } from 'express-validator/check'
2 import * as express from 'express'
3
4 import { logger } from '../../helpers'
5
6 function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction) {
7 const errors = validationResult(req)
8
9 if (!errors.isEmpty()) {
10 logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() })
11 return res.status(400).json({ errors: errors.mapped() })
12 }
13
14 return next()
15 }
16
17 function areValidationErrors (req: express.Request, res: express.Response) {
18 const errors = validationResult(req)
19
20 if (!errors.isEmpty()) {
21 logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() })
22 res.status(400).json({ errors: errors.mapped() })
23
24 return true
25 }
26
27 return false
28 }
29
30 // ---------------------------------------------------------------------------
31
32 export {
33 checkErrors,
34 areValidationErrors
35 }