diff options
Diffstat (limited to 'server/middlewares/validators/utils.ts')
-rw-r--r-- | server/middlewares/validators/utils.ts | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts index 4167f6d43..e291f1b17 100644 --- a/server/middlewares/validators/utils.ts +++ b/server/middlewares/validators/utils.ts | |||
@@ -1,15 +1,19 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query, validationResult } from 'express-validator' | 2 | import { query, validationResult } from 'express-validator' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
5 | 4 | ||
6 | function areValidationErrors (req: express.Request, res: express.Response) { | 5 | function areValidationErrors (req: express.Request, res: express.Response) { |
7 | const errors = validationResult(req) | 6 | const errors = validationResult(req) |
8 | 7 | ||
9 | if (!errors.isEmpty()) { | 8 | if (!errors.isEmpty()) { |
10 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() }) | 9 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() }) |
11 | res.status(HttpStatusCode.BAD_REQUEST_400) | 10 | res.fail({ |
12 | .json({ errors: errors.mapped() }) | 11 | message: 'Incorrect request parameters: ' + Object.keys(errors.mapped()).join(', '), |
12 | instance: req.originalUrl, | ||
13 | data: { | ||
14 | 'invalid-params': errors.mapped() | ||
15 | } | ||
16 | }) | ||
13 | 17 | ||
14 | return true | 18 | return true |
15 | } | 19 | } |