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

534
Visualizações
What's difference between Promise.reject(error) and return error in Axios?

I have a general query about Axios and Promises. Maybe someone can help me clear this concept.

Basic Interceptor of Axios includes:

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });

My question is what's the difference between returning error as

Project.reject(error);

and as

return error;

This response and error goes to the Request 'then' amd 'catch' blocks respectively I believe. But what's the difference if we use Promise.resolve and Promise.reject?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I just tried (it's that easy!) and the difference is that by returning a rejected promise (return Promise.reject(error)), you tell axios that the response has an error condition and that the upstream code should be notified about it (axios(…).catch(…) will trigger).

When returning just the error (return error), you're telling axios to basically ignore the error and the upstream code will not know about it (axios(…).then(…) will trigger).

about 4 years ago · Santiago Trujillo Relatório
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