diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-07 14:32:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 14:32:36 +0100 |
commit | 2d53be0267acc49cda46707b885096193a1f4e9c (patch) | |
tree | 887061a34bc67f40acbb96a6278f9544bf83caeb /server/middlewares/validators/utils.ts | |
parent | adc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff) | |
download | PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip |
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/middlewares/validators/utils.ts')
-rw-r--r-- | server/middlewares/validators/utils.ts | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts index 43e5652fa..2899bed6f 100644 --- a/server/middlewares/validators/utils.ts +++ b/server/middlewares/validators/utils.ts | |||
@@ -1,13 +1,15 @@ | |||
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' | ||
4 | 5 | ||
5 | function areValidationErrors (req: express.Request, res: express.Response) { | 6 | function areValidationErrors (req: express.Request, res: express.Response) { |
6 | const errors = validationResult(req) | 7 | const errors = validationResult(req) |
7 | 8 | ||
8 | if (!errors.isEmpty()) { | 9 | if (!errors.isEmpty()) { |
9 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() }) | 10 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() }) |
10 | res.status(400).json({ errors: errors.mapped() }) | 11 | res.status(HttpStatusCode.BAD_REQUEST_400) |
12 | .json({ errors: errors.mapped() }) | ||
11 | 13 | ||
12 | return true | 14 | return true |
13 | } | 15 | } |