Мне нужно реализовать функцию с использованием вложенных fetch запросов. Получаю следующие ошибки
Failed to load resource: the server responded with a status of 404 (Not Found);
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
async function getCart() {
fetch(base_api_path + '/cart/getAllOrders', {method: 'GET'})
.then(res => res.json())
.then(res => {
res.forEach(income => {
.....
fetch(base_api_path+'/cart/getItems',
{
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(
{
id: income.itemId
}
)
})
.then(res => res.json())
.then(res => {
res.forEach(intel => {
.....
})
})
})
}
Подскажите, можно ли вообще использовать fetch внутри fetch, и в чем моя ошибка?
exports.getAllOrders = async function (req, res) {
if(req.user){
const allOrders = await Orders.findAll({ where: { userId: req.user.id } })
res.send(JSON.stringify(allOrders)) }
}
exports.getItems = async function (req, res) {
const allItems = await Items.findAll({ where: { id: req.body.id } })
res.send(JSON.stringify(allItems));
}
res.json()
падает