1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

replace numbers with typed http status codes (#3409)

This commit is contained in:
Rigel Kent 2020-12-07 14:32:36 +01:00 committed by GitHub
parent adc1f09c0d
commit 2d53be0267
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
149 changed files with 1721 additions and 1108 deletions

View file

@ -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()