1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 02:09:37 +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

@ -100,7 +100,7 @@ function getPluginTranslations (req: express.Request, res: express.Response) {
return res.json(json)
}
return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
return res.status(HttpStatusCode.NOT_FOUND_404).end()
}
function servePluginStaticDirectory (req: express.Request, res: express.Response) {
@ -110,7 +110,7 @@ function servePluginStaticDirectory (req: express.Request, res: express.Response
const [ directory, ...file ] = staticEndpoint.split('/')
const staticPath = plugin.staticDirs[directory]
if (!staticPath) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
if (!staticPath) return res.status(HttpStatusCode.NOT_FOUND_404).end()
const filepath = file.join('/')
return res.sendFile(join(plugin.path, staticPath, filepath), sendFileOptions)
@ -120,7 +120,7 @@ function servePluginCustomRoutes (req: express.Request, res: express.Response, n
const plugin: RegisteredPlugin = res.locals.registeredPlugin
const router = PluginManager.Instance.getRouter(plugin.npmName)
if (!router) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
if (!router) return res.status(HttpStatusCode.NOT_FOUND_404).end()
return router(req, res, next)
}
@ -130,7 +130,7 @@ function servePluginClientScripts (req: express.Request, res: express.Response)
const staticEndpoint = req.params.staticEndpoint
const file = plugin.clientScripts[staticEndpoint]
if (!file) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
if (!file) return res.status(HttpStatusCode.NOT_FOUND_404).end()
return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions)
}
@ -140,7 +140,7 @@ function serveThemeCSSDirectory (req: express.Request, res: express.Response) {
const staticEndpoint = req.params.staticEndpoint
if (plugin.css.includes(staticEndpoint) === false) {
return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
return res.status(HttpStatusCode.NOT_FOUND_404).end()
}
return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions)