Handling 302 status/redirect
See original GitHub issueI’ve posted this on stackoverflow but I’ll ask here as well.
I have a POST request which returns a 302 when successful. I need to get the location response header which holds the url I’ll need to redirect to. Currently I have this:
accountLogin: builder.mutation<any, any>({
query: (body) => ({
url: `/accounts/login`,
method: 'POST',
body,
responseHandler: (response) => {
console.log(response, response.headers);
return response.text(); //.text() is just for testing purposes
},
}),
}),
If I look in the network tab of my browser the 302 is there, as is the location header with the proper URL. But the ‘console.log’ in responseHandler shows no headers. I can’t find much about this in the documentation – what am I missing?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How does HTTP 302 work? - Stack Overflow
The server returns an HTTP response with the code 302 , indicating a temporary redirection, and includes a Location: header indicating the ...
Read more >302 Found - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 302 Found redirect status response code indicates that the resource requested has been temporarily ...
Read more >How To Fix the HTTP 302 Error (5 Methods) - Kinsta
HTTP 302 status codes are a completely normal way to redirect your website visitors. However, they should only be used when the resource...
Read more >When to Use a 301 Redirect vs. 302 Redirect - seoClarity
A 302 redirect is a temporary redirect and directs users and search engines to the desired page for a limited amount of time...
Read more >302 Found: What It Is and How to Fix It - Airbrake Blog
A 302 Found message is an HTTP response status code indicating that the requested resource has been temporarily moved to a different URI....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
fetchBaseQuery
accepts all options that you can also pass intofetch
and passes those intofetch
.If
fetch
follows, that happens internally within that, so RTK Query will never even see the302
.See https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#parameters
Essentially: try to make the
fetch
call by hand - if that works it should also work with RTKQ.Apart from that, maybe an XHR wrapper like axios might do the trick. Not sure.