✅ – dmikester1 – 20-34 Jan 31

Ddmikester11/31/2023
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 });
});

I cannot get the filled in linesQCCheckStatus array to get passed back.
Ddmikester11/31/2023
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.
Ddmikester11/31/2023
This is my client code where the call is made:
Ddmikester11/31/2023
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 });
};
Ddmikester11/31/2023
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 = {};
UUUnknown User2/1/2023
3 Messages Not Public
Sign In & Join Server To View