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

228
Views
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
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!