PeerTube/server/middlewares/reqValidators/utils.js

26 lines
642 B
JavaScript
Raw Normal View History

'use strict'
2015-11-07 07:16:26 -06:00
2016-03-16 16:29:27 -05:00
const util = require('util')
2016-01-31 04:23:52 -06:00
2016-03-16 16:29:27 -05:00
const logger = require('../../helpers/logger')
2015-11-07 07:16:26 -06:00
2016-03-16 16:29:27 -05:00
const reqValidatorsUtils = {
checkErrors: checkErrors
}
2015-11-07 07:16:26 -06:00
function checkErrors (req, res, next, status_code) {
if (status_code === undefined) status_code = 400
2016-03-16 16:29:27 -05:00
const errors = req.validationErrors()
2015-11-07 07:16:26 -06:00
if (errors) {
logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors })
return res.status(status_code).send('There have been validation errors: ' + util.inspect(errors))
2015-11-07 07:16:26 -06:00
}
return next()
}
// ---------------------------------------------------------------------------
2016-01-31 04:23:52 -06:00
module.exports = reqValidatorsUtils