diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2021-06-01 01:36:53 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-06-02 16:57:07 +0200 |
commit | 76148b27f7501bac061992136852be4303370c8d (patch) | |
tree | fc0559253e833c9252fa14ebaec5321d88bfb4e8 /server/helpers/custom-validators/video-comments.ts | |
parent | 5ed25fb76e920dac364cb9ef46f14ec4bd372949 (diff) | |
download | PeerTube-76148b27f7501bac061992136852be4303370c8d.tar.gz PeerTube-76148b27f7501bac061992136852be4303370c8d.tar.zst PeerTube-76148b27f7501bac061992136852be4303370c8d.zip |
refactor API errors to standard error format
Diffstat (limited to 'server/helpers/custom-validators/video-comments.ts')
-rw-r--r-- | server/helpers/custom-validators/video-comments.ts | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/server/helpers/custom-validators/video-comments.ts b/server/helpers/custom-validators/video-comments.ts index 8d3ce580e..5c88447ad 100644 --- a/server/helpers/custom-validators/video-comments.ts +++ b/server/helpers/custom-validators/video-comments.ts | |||
@@ -16,26 +16,20 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide | |||
16 | const videoComment = await VideoCommentModel.loadById(id) | 16 | const videoComment = await VideoCommentModel.loadById(id) |
17 | 17 | ||
18 | if (!videoComment) { | 18 | if (!videoComment) { |
19 | res.status(HttpStatusCode.NOT_FOUND_404) | 19 | res.fail({ |
20 | .json({ error: 'Video comment thread not found' }) | 20 | status: HttpStatusCode.NOT_FOUND_404, |
21 | .end() | 21 | message: 'Video comment thread not found' |
22 | 22 | }) | |
23 | return false | 23 | return false |
24 | } | 24 | } |
25 | 25 | ||
26 | if (videoComment.videoId !== video.id) { | 26 | if (videoComment.videoId !== video.id) { |
27 | res.status(HttpStatusCode.BAD_REQUEST_400) | 27 | res.fail({ message: 'Video comment is not associated to this video.' }) |
28 | .json({ error: 'Video comment is not associated to this video.' }) | ||
29 | .end() | ||
30 | |||
31 | return false | 28 | return false |
32 | } | 29 | } |
33 | 30 | ||
34 | if (videoComment.inReplyToCommentId !== null) { | 31 | if (videoComment.inReplyToCommentId !== null) { |
35 | res.status(HttpStatusCode.BAD_REQUEST_400) | 32 | res.fail({ message: 'Video comment is not a thread.' }) |
36 | .json({ error: 'Video comment is not a thread.' }) | ||
37 | .end() | ||
38 | |||
39 | return false | 33 | return false |
40 | } | 34 | } |
41 | 35 | ||
@@ -48,18 +42,15 @@ async function doesVideoCommentExist (idArg: number | string, video: MVideoId, r | |||
48 | const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) | 42 | const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) |
49 | 43 | ||
50 | if (!videoComment) { | 44 | if (!videoComment) { |
51 | res.status(HttpStatusCode.NOT_FOUND_404) | 45 | res.fail({ |
52 | .json({ error: 'Video comment thread not found' }) | 46 | status: HttpStatusCode.NOT_FOUND_404, |
53 | .end() | 47 | message: 'Video comment thread not found' |
54 | 48 | }) | |
55 | return false | 49 | return false |
56 | } | 50 | } |
57 | 51 | ||
58 | if (videoComment.videoId !== video.id) { | 52 | if (videoComment.videoId !== video.id) { |
59 | res.status(HttpStatusCode.BAD_REQUEST_400) | 53 | res.fail({ message: 'Video comment is not associated to this video.' }) |
60 | .json({ error: 'Video comment is not associated to this video.' }) | ||
61 | .end() | ||
62 | |||
63 | return false | 54 | return false |
64 | } | 55 | } |
65 | 56 | ||
@@ -72,14 +63,14 @@ async function doesCommentIdExist (idArg: number | string, res: express.Response | |||
72 | const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) | 63 | const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) |
73 | 64 | ||
74 | if (!videoComment) { | 65 | if (!videoComment) { |
75 | res.status(HttpStatusCode.NOT_FOUND_404) | 66 | res.fail({ |
76 | .json({ error: 'Video comment thread not found' }) | 67 | status: HttpStatusCode.NOT_FOUND_404, |
77 | 68 | message: 'Video comment thread not found' | |
69 | }) | ||
78 | return false | 70 | return false |
79 | } | 71 | } |
80 | 72 | ||
81 | res.locals.videoCommentFull = videoComment | 73 | res.locals.videoCommentFull = videoComment |
82 | |||
83 | return true | 74 | return true |
84 | } | 75 | } |
85 | 76 | ||