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

227
Visualizações
How to prevent/handle auto redirection on api calls with fetch

I am trying to access the api but for accessing the api I need token so When I try to hit the api it redirects to the auth page.

I can see the redirection is happening in the network tab.

is there any way to prevent this?

I wanted to get the 302 error code when I first hit the api(its giving 302 but with fetch/Redirect) but because of automatic redirection its throwing error and going to error block always.

fetch(url, { method: 'POST', redirect: 'error'})
.then(response => {
    // handle 302 response
})
.catch(function(err) {
    console.info(err);
});

Edit: To get the token I need to redirect user to the auth page. so once I get the 302 error Ill redirect the user to the auth page.

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