dmikester1
dmikester12y ago

✅ – dmikester1 – 20-34 Jan 31

I have a route in my Node server with this code:
router.get('/getLinesQCWarningStatus', async (req, res) => {
let linesQCCheckStatus = [];
for (const area of lineAreas) {
const checkID = await storage.getItem('checkID-' + area);
// ... add some stuff to linesQCCheckStatus
console.log({ linesQCCheckStatus });
}
console.log('sending back: ', linesQCCheckStatus);
res.send({ statuses: linesQCCheckStatus });
});
router.get('/getLinesQCWarningStatus', async (req, res) => {
let linesQCCheckStatus = [];
for (const area of lineAreas) {
const checkID = await storage.getItem('checkID-' + area);
// ... add some stuff to linesQCCheckStatus
console.log({ linesQCCheckStatus });
}
console.log('sending back: ', linesQCCheckStatus);
res.send({ statuses: linesQCCheckStatus });
});
I cannot get the filled in linesQCCheckStatus array to get passed back.
3 Replies
dmikester1
dmikester12y ago
The console logs are outputting correctly as I would expect. But in my client code where I make the call, it is always an empty array. This is my client code where the call is made:
export const getLinesQCWarningStatus = async (orderID) => {
const getLinesQCWarningStatusURL =
serverURL + `:${port}/getLinesQCWarningStatus`;
const result = await axios({
method: 'get',
url: getLinesQCWarningStatusURL,
timeout: medTimeout,
})
.then((res) => {
console.log({ res });
return res;
})
.catch((e) => {
// eslint-disable-next-line quotes
return Promise.reject(
'Unable to get Lines QC Warning Status from DB. - ' + e
);
});
console.log({ result });
};
export const getLinesQCWarningStatus = async (orderID) => {
const getLinesQCWarningStatusURL =
serverURL + `:${port}/getLinesQCWarningStatus`;
const result = await axios({
method: 'get',
url: getLinesQCWarningStatusURL,
timeout: medTimeout,
})
.then((res) => {
console.log({ res });
return res;
})
.catch((e) => {
// eslint-disable-next-line quotes
return Promise.reject(
'Unable to get Lines QC Warning Status from DB. - ' + e
);
});
console.log({ result });
};
Wow, that was a super tough one to debug!!! Actually had nothing to do with await/async/promises. What I was doing wrong was handling the array like an object. So the console log looked fine, but it wasn't passing it back correctly. All I had to do to fix it was change the array to an object: let linesQCCheckStatus = {};
reactibot
reactibot2y ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1070079624433914016
reactibot
reactibot2y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1070079624433914016 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26