Fix any components
This commit is contained in:
parent
9db7a4127f
commit
29fec9506b
@ -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);
|
||||
}
|
||||
}*/
|
||||
});
|
||||
|
||||
// Методы
|
||||
|
17
server.js
17
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();
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user