Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda