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

refactor API errors to standard error format

This commit is contained in:
Rigel Kent 2021-06-01 01:36:53 +02:00 committed by Chocobozzz
parent 5ed25fb76e
commit 76148b27f7
75 changed files with 785 additions and 547 deletions

View file

@ -16,26 +16,20 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide
const videoComment = await VideoCommentModel.loadById(id)
if (!videoComment) {
res.status(HttpStatusCode.NOT_FOUND_404)
.json({ error: 'Video comment thread not found' })
.end()
res.fail({
status: HttpStatusCode.NOT_FOUND_404,
message: 'Video comment thread not found'
})
return false
}
if (videoComment.videoId !== video.id) {
res.status(HttpStatusCode.BAD_REQUEST_400)
.json({ error: 'Video comment is not associated to this video.' })
.end()
res.fail({ message: 'Video comment is not associated to this video.' })
return false
}
if (videoComment.inReplyToCommentId !== null) {
res.status(HttpStatusCode.BAD_REQUEST_400)
.json({ error: 'Video comment is not a thread.' })
.end()
res.fail({ message: 'Video comment is not a thread.' })
return false
}
@ -48,18 +42,15 @@ async function doesVideoCommentExist (idArg: number | string, video: MVideoId, r
const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
if (!videoComment) {
res.status(HttpStatusCode.NOT_FOUND_404)
.json({ error: 'Video comment thread not found' })
.end()
res.fail({
status: HttpStatusCode.NOT_FOUND_404,
message: 'Video comment thread not found'
})
return false
}
if (videoComment.videoId !== video.id) {
res.status(HttpStatusCode.BAD_REQUEST_400)
.json({ error: 'Video comment is not associated to this video.' })
.end()
res.fail({ message: 'Video comment is not associated to this video.' })
return false
}
@ -72,14 +63,14 @@ async function doesCommentIdExist (idArg: number | string, res: express.Response
const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
if (!videoComment) {
res.status(HttpStatusCode.NOT_FOUND_404)
.json({ error: 'Video comment thread not found' })
res.fail({
status: HttpStatusCode.NOT_FOUND_404,
message: 'Video comment thread not found'
})
return false
}
res.locals.videoCommentFull = videoComment
return true
}