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/middlewares/validators/blocklist.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/middlewares/validators/blocklist.ts')
-rw-r--r-- | server/middlewares/validators/blocklist.ts | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index f61811a1a..125ff882c 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts | |||
@@ -24,9 +24,10 @@ const blockAccountValidator = [ | |||
24 | const accountToBlock = res.locals.account | 24 | const accountToBlock = res.locals.account |
25 | 25 | ||
26 | if (user.Account.id === accountToBlock.id) { | 26 | if (user.Account.id === accountToBlock.id) { |
27 | res.status(HttpStatusCode.CONFLICT_409) | 27 | res.fail({ |
28 | .json({ error: 'You cannot block yourself.' }) | 28 | status: HttpStatusCode.CONFLICT_409, |
29 | 29 | message: 'You cannot block yourself.' | |
30 | }) | ||
30 | return | 31 | return |
31 | } | 32 | } |
32 | 33 | ||
@@ -79,8 +80,10 @@ const blockServerValidator = [ | |||
79 | const host: string = req.body.host | 80 | const host: string = req.body.host |
80 | 81 | ||
81 | if (host === WEBSERVER.HOST) { | 82 | if (host === WEBSERVER.HOST) { |
82 | return res.status(HttpStatusCode.CONFLICT_409) | 83 | return res.fail({ |
83 | .json({ error: 'You cannot block your own server.' }) | 84 | status: HttpStatusCode.CONFLICT_409, |
85 | message: 'You cannot block your own server.' | ||
86 | }) | ||
84 | } | 87 | } |
85 | 88 | ||
86 | const server = await ServerModel.loadOrCreateByHost(host) | 89 | const server = await ServerModel.loadOrCreateByHost(host) |
@@ -137,27 +140,27 @@ export { | |||
137 | async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) { | 140 | async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) { |
138 | const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) | 141 | const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) |
139 | if (!accountBlock) { | 142 | if (!accountBlock) { |
140 | res.status(HttpStatusCode.NOT_FOUND_404) | 143 | res.fail({ |
141 | .json({ error: 'Account block entry not found.' }) | 144 | status: HttpStatusCode.NOT_FOUND_404, |
142 | 145 | message: 'Account block entry not found.' | |
146 | }) | ||
143 | return false | 147 | return false |
144 | } | 148 | } |
145 | 149 | ||
146 | res.locals.accountBlock = accountBlock | 150 | res.locals.accountBlock = accountBlock |
147 | |||
148 | return true | 151 | return true |
149 | } | 152 | } |
150 | 153 | ||
151 | async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) { | 154 | async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) { |
152 | const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) | 155 | const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) |
153 | if (!serverBlock) { | 156 | if (!serverBlock) { |
154 | res.status(HttpStatusCode.NOT_FOUND_404) | 157 | res.fail({ |
155 | .json({ error: 'Server block entry not found.' }) | 158 | status: HttpStatusCode.NOT_FOUND_404, |
156 | 159 | message: 'Server block entry not found.' | |
160 | }) | ||
157 | return false | 161 | return false |
158 | } | 162 | } |
159 | 163 | ||
160 | res.locals.serverBlock = serverBlock | 164 | res.locals.serverBlock = serverBlock |
161 | |||
162 | return true | 165 | return true |
163 | } | 166 | } |