From a2eb7432228918c98bc46b5d4b58b51f4f8e7dde Mon Sep 17 00:00:00 2001 From: SmilerRyan Date: Mon, 2 Sep 2024 05:16:11 +0100 Subject: [PATCH] api: update /api/best_audio route error handling --- src/core/api.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/api.js b/src/core/api.js index 2f873cd0..649dc21f 100644 --- a/src/core/api.js +++ b/src/core/api.js @@ -145,6 +145,13 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { app.get('/api/best_audio', async (req, res) => { + const lang = languageCode(req); + + const fail = (t) => { + const { status, body } = createResponse("error", { t: loc(lang, t) }); + res.status(status).json(body); + } + if (!req.query.url) { return res.status(400).send('Missing required "url" query parameter'); } const request = req.query; @@ -168,7 +175,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { fail('ErrorSomethingWentWrong'); } }) - + app.get('/api/stream', (req, res) => { const id = String(req.query.id); const exp = String(req.query.exp);