From 2d53be0267acc49cda46707b885096193a1f4e9c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 7 Dec 2020 14:32:36 +0100 Subject: replace numbers with typed http status codes (#3409) --- server/middlewares/validators/follows.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'server/middlewares/validators/follows.ts') 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 import { MActorFollowActorsDefault } from '@server/types/models' import { isFollowStateValid } from '@server/helpers/custom-validators/follows' import { getServerActor } from '@server/models/application/application' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' const listFollowsValidator = [ query('state') @@ -34,7 +35,8 @@ const followValidator = [ (req: express.Request, res: express.Response, next: express.NextFunction) => { // Force https if the administrator wants to make friends if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') { - return res.status(500) + return res + .status(HttpStatusCode.INTERNAL_SERVER_ERROR_500) .json({ error: 'Cannot follow on a non HTTPS web server.' }) @@ -62,7 +64,7 @@ const removeFollowingValidator = [ if (!follow) { return res - .status(404) + .status(HttpStatusCode.NOT_FOUND_404) .json({ error: `Following ${req.params.host} not found.` }) @@ -95,7 +97,7 @@ const getFollowerValidator = [ if (!follow) { return res - .status(404) + .status(HttpStatusCode.NOT_FOUND_404) .json({ error: `Follower ${req.params.nameWithHost} not found.` }) @@ -113,7 +115,12 @@ const acceptOrRejectFollowerValidator = [ const follow = res.locals.follow if (follow.state !== 'pending') { - return res.status(400).json({ error: 'Follow is not in pending state.' }).end() + return res + .status(HttpStatusCode.BAD_REQUEST_400) + .json({ + error: 'Follow is not in pending state.' + }) + .end() } return next() -- cgit v1.2.3