aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/plugins.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server/controllers/api/plugins.ts
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/controllers/api/plugins.ts')
-rw-r--r--server/controllers/api/plugins.ts11
1 files changed, 6 insertions, 5 deletions
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts
index f8a0d19ca..1c0b5edb1 100644
--- a/server/controllers/api/plugins.ts
+++ b/server/controllers/api/plugins.ts
@@ -27,6 +27,7 @@ import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index'
27import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model' 27import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model'
28import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model' 28import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model'
29import { PublicServerSetting } from '../../../shared/models/plugins/public-server.setting' 29import { PublicServerSetting } from '../../../shared/models/plugins/public-server.setting'
30import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
30 31
31const pluginRouter = express.Router() 32const pluginRouter = express.Router()
32 33
@@ -140,7 +141,7 @@ async function installPlugin (req: express.Request, res: express.Response) {
140 return res.json(plugin.toFormattedJSON()) 141 return res.json(plugin.toFormattedJSON())
141 } catch (err) { 142 } catch (err) {
142 logger.warn('Cannot install plugin %s.', toInstall, { err }) 143 logger.warn('Cannot install plugin %s.', toInstall, { err })
143 return res.sendStatus(400) 144 return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
144 } 145 }
145} 146}
146 147
@@ -155,7 +156,7 @@ async function updatePlugin (req: express.Request, res: express.Response) {
155 return res.json(plugin.toFormattedJSON()) 156 return res.json(plugin.toFormattedJSON())
156 } catch (err) { 157 } catch (err) {
157 logger.warn('Cannot update plugin %s.', toUpdate, { err }) 158 logger.warn('Cannot update plugin %s.', toUpdate, { err })
158 return res.sendStatus(400) 159 return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
159 } 160 }
160} 161}
161 162
@@ -164,7 +165,7 @@ async function uninstallPlugin (req: express.Request, res: express.Response) {
164 165
165 await PluginManager.Instance.uninstall(body.npmName) 166 await PluginManager.Instance.uninstall(body.npmName)
166 167
167 return res.sendStatus(204) 168 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
168} 169}
169 170
170function getPublicPluginSettings (req: express.Request, res: express.Response) { 171function getPublicPluginSettings (req: express.Request, res: express.Response) {
@@ -193,7 +194,7 @@ async function updatePluginSettings (req: express.Request, res: express.Response
193 194
194 await PluginManager.Instance.onSettingsChanged(plugin.name, plugin.settings) 195 await PluginManager.Instance.onSettingsChanged(plugin.name, plugin.settings)
195 196
196 return res.sendStatus(204) 197 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
197} 198}
198 199
199async function listAvailablePlugins (req: express.Request, res: express.Response) { 200async function listAvailablePlugins (req: express.Request, res: express.Response) {
@@ -202,7 +203,7 @@ async function listAvailablePlugins (req: express.Request, res: express.Response
202 const resultList = await listAvailablePluginsFromIndex(query) 203 const resultList = await listAvailablePluginsFromIndex(query)
203 204
204 if (!resultList) { 205 if (!resultList) {
205 return res.status(503) 206 return res.status(HttpStatusCode.SERVICE_UNAVAILABLE_503)
206 .json({ error: 'Plugin index unavailable. Please retry later' }) 207 .json({ error: 'Plugin index unavailable. Please retry later' })
207 .end() 208 .end()
208 } 209 }