diff --git a/api/v1/index.js b/api/v1/index.js index 528e7ce..6141628 100644 --- a/api/v1/index.js +++ b/api/v1/index.js @@ -48,12 +48,15 @@ router.get('/music', async (req, res) => { res.send(Buffer.from([])); }); }); - -// middleware (Обработка типа ответа) +// middleware (Обработка ошибок типа ответа) router.use((req, res, next) => { const unknownResponseFormat = "UNKNOWN_RESPONSE_FORMAT"; + if (!res.result) { + return res.status(400).send(unknownResponseFormat); + } + next(); - if (!req.query.response_format) { + /*if (!req.query.response_format) { res.send(unknownResponseFormat); } else if (req.query.response_format === 'json') { @@ -68,7 +71,7 @@ router.use((req, res, next) => { } else { res.send(unknownResponseFormat); - } + }*/ }); // Методы diff --git a/server.js b/server.js index f507802..d6c3311 100644 --- a/server.js +++ b/server.js @@ -14,14 +14,15 @@ app.use(bodyParser.json({limit: config().request_size_limit})); app.use( (req, res, next) => { - // Поставил по-умолчанию - res.result = function (data, isErr = false, code = 200) { - this.status(code).json(!isErr ? { - response : data - } : { - error : data - }); - }; + if (req.query.response_format === 'json') { + res.result = function (data, isErr = false, code = 200) { + this.status(code).json(!isErr ? { + response : data + } : { + error : data + }); + }; + } next(); } );