✅ – 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.
D
dmikester1461d 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 = {};
UU
Unknown User460d ago