aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/follows.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server/middlewares/validators/follows.ts
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/middlewares/validators/follows.ts')
-rw-r--r--server/middlewares/validators/follows.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index 2c1ddf2df..a590aca99 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -12,6 +12,7 @@ import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-valid
12import { MActorFollowActorsDefault } from '@server/types/models' 12import { MActorFollowActorsDefault } from '@server/types/models'
13import { isFollowStateValid } from '@server/helpers/custom-validators/follows' 13import { isFollowStateValid } from '@server/helpers/custom-validators/follows'
14import { getServerActor } from '@server/models/application/application' 14import { getServerActor } from '@server/models/application/application'
15import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
15 16
16const listFollowsValidator = [ 17const listFollowsValidator = [
17 query('state') 18 query('state')
@@ -34,7 +35,8 @@ const followValidator = [
34 (req: express.Request, res: express.Response, next: express.NextFunction) => { 35 (req: express.Request, res: express.Response, next: express.NextFunction) => {
35 // Force https if the administrator wants to make friends 36 // Force https if the administrator wants to make friends
36 if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') { 37 if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') {
37 return res.status(500) 38 return res
39 .status(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
38 .json({ 40 .json({
39 error: 'Cannot follow on a non HTTPS web server.' 41 error: 'Cannot follow on a non HTTPS web server.'
40 }) 42 })
@@ -62,7 +64,7 @@ const removeFollowingValidator = [
62 64
63 if (!follow) { 65 if (!follow) {
64 return res 66 return res
65 .status(404) 67 .status(HttpStatusCode.NOT_FOUND_404)
66 .json({ 68 .json({
67 error: `Following ${req.params.host} not found.` 69 error: `Following ${req.params.host} not found.`
68 }) 70 })
@@ -95,7 +97,7 @@ const getFollowerValidator = [
95 97
96 if (!follow) { 98 if (!follow) {
97 return res 99 return res
98 .status(404) 100 .status(HttpStatusCode.NOT_FOUND_404)
99 .json({ 101 .json({
100 error: `Follower ${req.params.nameWithHost} not found.` 102 error: `Follower ${req.params.nameWithHost} not found.`
101 }) 103 })
@@ -113,7 +115,12 @@ const acceptOrRejectFollowerValidator = [
113 115
114 const follow = res.locals.follow 116 const follow = res.locals.follow
115 if (follow.state !== 'pending') { 117 if (follow.state !== 'pending') {
116 return res.status(400).json({ error: 'Follow is not in pending state.' }).end() 118 return res
119 .status(HttpStatusCode.BAD_REQUEST_400)
120 .json({
121 error: 'Follow is not in pending state.'
122 })
123 .end()
117 } 124 }
118 125
119 return next() 126 return next()