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

223
Views
Is it possible to convert a failing promise into a successful one?

I have a call in a Promise chain that might fail, and in certain conditions I want to ignore that error. Is it possible to tell the promise that it should continue as a success?

Like this:

function do() {
  return possiblyFailingCall.then(function(response) {
    // handle successful response
    return response.data;
  }, function (error) {
    if (error && error.statusCode === 404) {
      // ah, this is not really an error; I wanto to return an empty object now
      return {}; // <- this is where I want to return to the success-route
    } else {
      // this is actually an error that I want to pass on in the promise chain
    }
  });
}

do().then(function(data) {
  // in the case of the 404 (not found), I want to get an empty object
}, function(error) {
  // I do not want to see the 404 error here, but I want to see all other errors
});
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!