]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/utils.ts
Type functions
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / utils.ts
CommitLineData
69818c93
C
1import 'express-validator'
2import * as express from 'express'
65fcc311 3import { inspect } from 'util'
34ca3b52 4
65fcc311 5import { logger } from '../../helpers'
c45f7f84 6
69818c93 7function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction, statusCode = 400) {
f0f5567b 8 const errors = req.validationErrors()
34ca3b52 9
9f10b292
C
10 if (errors) {
11 logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors })
65fcc311 12 return res.status(statusCode).send('There have been validation errors: ' + inspect(errors))
34ca3b52
C
13 }
14
9f10b292
C
15 return next()
16}
17
18// ---------------------------------------------------------------------------
c45f7f84 19
65fcc311
C
20export {
21 checkErrors
22}