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/blocklist.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'server/middlewares/validators/blocklist.ts') diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index c24fa9609..f61811a1a 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts @@ -9,6 +9,7 @@ import { ServerModel } from '../../models/server/server' import { WEBSERVER } from '../../initializers/constants' import { doesAccountNameWithHostExist } from '../../helpers/middlewares' import { getServerActor } from '@server/models/application/application' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' const blockAccountValidator = [ body('accountName').exists().withMessage('Should have an account name with host'), @@ -23,7 +24,7 @@ const blockAccountValidator = [ const accountToBlock = res.locals.account if (user.Account.id === accountToBlock.id) { - res.status(409) + res.status(HttpStatusCode.CONFLICT_409) .json({ error: 'You cannot block yourself.' }) return @@ -78,7 +79,7 @@ const blockServerValidator = [ const host: string = req.body.host if (host === WEBSERVER.HOST) { - return res.status(409) + return res.status(HttpStatusCode.CONFLICT_409) .json({ error: 'You cannot block your own server.' }) } @@ -136,7 +137,7 @@ export { async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) { const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) if (!accountBlock) { - res.status(404) + res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Account block entry not found.' }) return false @@ -150,7 +151,7 @@ async function doesUnblockAccountExist (accountId: number, targetAccountId: numb async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) { const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) if (!serverBlock) { - res.status(404) + res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Server block entry not found.' }) return false -- cgit v1.2.3