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([]));
|
res.send(Buffer.from([]));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// middleware (Обработка ошибок типа ответа)
|
||||||
// middleware (Обработка типа ответа)
|
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
const unknownResponseFormat = "UNKNOWN_RESPONSE_FORMAT";
|
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);
|
res.send(unknownResponseFormat);
|
||||||
}
|
}
|
||||||
else if (req.query.response_format === 'json') {
|
else if (req.query.response_format === 'json') {
|
||||||
@ -68,7 +71,7 @@ router.use((req, res, next) => {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.send(unknownResponseFormat);
|
res.send(unknownResponseFormat);
|
||||||
}
|
}*/
|
||||||
});
|
});
|
||||||
|
|
||||||
// Методы
|
// Методы
|
||||||
|
17
server.js
17
server.js
@ -14,14 +14,15 @@ app.use(bodyParser.json({limit: config().request_size_limit}));
|
|||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
(req, res, next) => {
|
(req, res, next) => {
|
||||||
// Поставил по-умолчанию
|
if (req.query.response_format === 'json') {
|
||||||
res.result = function (data, isErr = false, code = 200) {
|
res.result = function (data, isErr = false, code = 200) {
|
||||||
this.status(code).json(!isErr ? {
|
this.status(code).json(!isErr ? {
|
||||||
response : data
|
response : data
|
||||||
} : {
|
} : {
|
||||||
error : data
|
error : data
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
}
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user