Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
error handling with array of promises fails to return custom errors

I'm calling an async function which returns an array of promises to deal with the fact that eslint won't let you use await in a for loop...

my function is passing strings from an array one by one into another function which is doing some encoding and then waiting for them all to finish before returning the final encoded values as you can imagine a few things screw up on the encoding side and that module will throw relevant errors as needed

my issue is that unfortunately, when returning an array of promises those errors will not show on the stack trace... the only error that I get back is a generic 500 server error but none of my custom errors show

async function decodedAddresses(req, addresses) {
  if (!Array.isArray(addresses)) {
    return decodeId(req, addressId, idType.address);
  }

  return Promise.all(
    addresses.map(id => {
      return decoded(req, id).then(addr => {
        return {
          address: addr,
        };
      });
    })
  ).
  });
}

however if I simply call my function and have it return this way without the array of promises I have no issues and all the errors appear on the stack trace

async function decodedAddresses(req, addresses) {
return decoded(req, id)
}

also the length of the addresses does not matter it can be an array[1] or array[2] etc... the same issue occurs, I'm hoping someone might have some insight into why an array of promises may somehow be overwriting or not placing these errors on the stack

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!