]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/utils.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / utils.ts
index 710e65529684d5633a03fb630da7d7ab00328818..ea107bbe8f67b5036b7f24a964d470de76b7d968 100644 (file)
@@ -1,14 +1,14 @@
-import { inspect } from 'util'
+import { validationResult } from 'express-validator/check'
+import * as express from 'express'
 
 import { logger } from '../../helpers'
 
-function checkErrors (req, res, next, statusCode?) {
-  if (statusCode === undefined) statusCode = 400
-  const errors = req.validationErrors()
+function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction) {
+  const errors = validationResult(req)
 
-  if (errors) {
-    logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors })
-    return res.status(statusCode).send('There have been validation errors: ' + inspect(errors))
+  if (!errors.isEmpty()) {
+    logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() })
+    return res.status(400).json({ errors: errors.mapped() })
   }
 
   return next()