]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - middlewares/reqValidators/utils.js
Infile code reorganization
[github/Chocobozzz/PeerTube.git] / middlewares / reqValidators / utils.js
CommitLineData
34ca3b52
C
1;(function () {
2 'use strict'
3
4 var util = require('util')
c45f7f84 5
cda02107 6 var logger = require('../../helpers/logger')
34ca3b52 7
c45f7f84
C
8 var reqValidatorsUtils = {
9 checkErrors: checkErrors
10 }
34ca3b52 11
c45f7f84 12 function checkErrors (req, res, next, status_code) {
34ca3b52
C
13 if (status_code === undefined) status_code = 400
14 var errors = req.validationErrors()
15
16 if (errors) {
17 logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors })
18 return res.status(status_code).send('There have been validation errors: ' + util.inspect(errors))
19 }
20
21 return next()
22 }
23
c45f7f84
C
24 // ---------------------------------------------------------------------------
25
26 module.exports = reqValidatorsUtils
34ca3b52 27})()