mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
replace numbers with typed http status codes (#3409)
This commit is contained in:
parent
adc1f09c0d
commit
2d53be0267
149 changed files with 1721 additions and 1108 deletions
|
@ -7,6 +7,7 @@ import { getOrCreateActorAndServerAndModel } from '../lib/activitypub/actor'
|
|||
import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger'
|
||||
import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor'
|
||||
import { getAPId } from '@server/helpers/activitypub'
|
||||
import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
async function checkSignature (req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
|
@ -28,11 +29,11 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
|
|||
const activity: ActivityDelete = req.body
|
||||
if (isActorDeleteActivityValid(activity) && activity.object === activity.actor) {
|
||||
logger.debug('Handling signature error on actor delete activity', { err })
|
||||
return res.sendStatus(204)
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
||||
logger.warn('Error in ActivityPub signature checker.', { err })
|
||||
return res.sendStatus(403)
|
||||
return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,13 +71,13 @@ async function checkHttpSignature (req: Request, res: Response) {
|
|||
} catch (err) {
|
||||
logger.warn('Invalid signature because of exception in signature parser', { reqBody: req.body, err })
|
||||
|
||||
res.status(403).json({ error: err.message })
|
||||
res.status(HttpStatusCode.FORBIDDEN_403).json({ error: err.message })
|
||||
return false
|
||||
}
|
||||
|
||||
const keyId = parsed.keyId
|
||||
if (!keyId) {
|
||||
res.sendStatus(403)
|
||||
res.sendStatus(HttpStatusCode.FORBIDDEN_403)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -93,7 +94,7 @@ async function checkHttpSignature (req: Request, res: Response) {
|
|||
if (verified !== true) {
|
||||
logger.warn('Signature from %s is invalid', actorUrl, { parsed })
|
||||
|
||||
res.sendStatus(403)
|
||||
res.sendStatus(HttpStatusCode.FORBIDDEN_403)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -106,7 +107,7 @@ async function checkJsonLDSignature (req: Request, res: Response) {
|
|||
const signatureObject: ActivityPubSignature = req.body.signature
|
||||
|
||||
if (!signatureObject || !signatureObject.creator) {
|
||||
res.sendStatus(403)
|
||||
res.sendStatus(HttpStatusCode.FORBIDDEN_403)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -120,7 +121,7 @@ async function checkJsonLDSignature (req: Request, res: Response) {
|
|||
if (verified !== true) {
|
||||
logger.warn('Signature not verified.', req.body)
|
||||
|
||||
res.sendStatus(403)
|
||||
res.sendStatus(HttpStatusCode.FORBIDDEN_403)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue