aboutsummaryrefslogtreecommitdiffhomepage
path: root/middlewares/reqValidators/utils.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-11-07 14:16:26 +0100
committerChocobozzz <florian.bigard@gmail.com>2015-11-07 14:16:26 +0100
commit34ca3b5225479a5da986c86ee4c42a73ae6df5ad (patch)
tree561ba5ae1adccd5729305a8cc17d13d24a0c2ddb /middlewares/reqValidators/utils.js
parentf5a60a5138135a3412dfbcfd6e564f7aa47a55c2 (diff)
downloadPeerTube-34ca3b5225479a5da986c86ee4c42a73ae6df5ad.tar.gz
PeerTube-34ca3b5225479a5da986c86ee4c42a73ae6df5ad.tar.zst
PeerTube-34ca3b5225479a5da986c86ee4c42a73ae6df5ad.zip
Add requests parameters validations
Diffstat (limited to 'middlewares/reqValidators/utils.js')
-rw-r--r--middlewares/reqValidators/utils.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/middlewares/reqValidators/utils.js b/middlewares/reqValidators/utils.js
new file mode 100644
index 000000000..91ead27a5
--- /dev/null
+++ b/middlewares/reqValidators/utils.js
@@ -0,0 +1,22 @@
1;(function () {
2 'use strict'
3
4 var util = require('util')
5 var logger = require('../../src/logger')
6
7 var utils = {}
8
9 utils.checkErrors = function (req, res, next, status_code) {
10 if (status_code === undefined) status_code = 400
11 var errors = req.validationErrors()
12
13 if (errors) {
14 logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors })
15 return res.status(status_code).send('There have been validation errors: ' + util.inspect(errors))
16 }
17
18 return next()
19 }
20
21 module.exports = utils
22})()