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

@ -13,6 +13,7 @@ import {
} from '@server/types/plugins/register-server-auth.model'
import * as express from 'express'
import * as OAuthServer from 'express-oauth-server'
import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
const oAuthServer = new OAuthServer({
useErrorHandler: true,
@ -215,7 +216,7 @@ function proxifyExternalAuthBypass (req: express.Request, res: express.Response)
const obj = authBypassTokens.get(req.body.externalAuthToken)
if (!obj) {
logger.error('Cannot authenticate user with unknown bypass token')
return res.sendStatus(400)
return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
}
const { expires, user, authName, npmName } = obj
@ -223,12 +224,12 @@ function proxifyExternalAuthBypass (req: express.Request, res: express.Response)
const now = new Date()
if (now.getTime() > expires.getTime()) {
logger.error('Cannot authenticate user with an expired external auth token')
return res.sendStatus(400)
return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
}
if (user.username !== req.body.username) {
logger.error('Cannot authenticate user %s with invalid username %s.', req.body.username)
return res.sendStatus(400)
return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
}
// Bypass oauth library validation

View file

@ -22,6 +22,7 @@ import * as Bluebird from 'bluebird'
import { CONFIG } from '../initializers/config'
import { logger } from '../helpers/logger'
import { MAccountActor, MChannelActor } from '../types/models'
import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
type Tags = {
ogType: string
@ -75,7 +76,7 @@ export class ClientHtml {
static async getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) {
// Let Angular application handle errors
if (!validator.isInt(videoId) && !validator.isUUID(videoId, 4)) {
res.status(404)
res.status(HttpStatusCode.NOT_FOUND_404)
return ClientHtml.getIndexHTML(req, res)
}
@ -86,7 +87,7 @@ export class ClientHtml {
// Let Angular application handle errors
if (!video || video.privacy === VideoPrivacy.PRIVATE || video.privacy === VideoPrivacy.INTERNAL || video.VideoBlacklist) {
res.status(404)
res.status(HttpStatusCode.NOT_FOUND_404)
return html
}
@ -121,7 +122,7 @@ export class ClientHtml {
static async getWatchPlaylistHTMLPage (videoPlaylistId: string, req: express.Request, res: express.Response) {
// Let Angular application handle errors
if (!validator.isInt(videoPlaylistId) && !validator.isUUID(videoPlaylistId, 4)) {
res.status(404)
res.status(HttpStatusCode.NOT_FOUND_404)
return ClientHtml.getIndexHTML(req, res)
}
@ -132,7 +133,7 @@ export class ClientHtml {
// Let Angular application handle errors
if (!videoPlaylist || videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) {
res.status(404)
res.status(HttpStatusCode.NOT_FOUND_404)
return html
}
@ -201,7 +202,7 @@ export class ClientHtml {
// Let Angular application handle errors
if (!entity) {
res.status(404)
res.status(HttpStatusCode.NOT_FOUND_404)
return ClientHtml.getIndexHTML(req, res)
}