Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I capture 302? #1806

Open
zystudios opened this issue May 24, 2024 · 2 comments
Open

How can I capture 302? #1806

zystudios opened this issue May 24, 2024 · 2 comments

Comments

@zystudios
Copy link

zystudios commented May 24, 2024

I request an API, this API will return 302, and automatically jump to another API, and then return data, but I see status code has been 200, I need to capture 302 to do some operations, what should I do?

thanks

@zystudios zystudios changed the title How can I catch 302? How can I capture 302? May 25, 2024
@woaer
Copy link

woaer commented May 27, 2024

You can use the following code:

http
  .get('http://example.com/')
  // following redirects
  .redirects(0)
  // error handling
  .ok(res => res.status >= 200 && res.status < 400)
  .then(res => {
    console.log(res.status)
    console.log(res.headers['location'])
  })

Reference documentation:
Following Redirects: SuperAgent Documentation
Error Handling: SuperAgent Documentation

@zystudios
Copy link
Author

You can use the following code:

http
  .get('http://example.com/')
  // following redirects
  .redirects(0)
  // error handling
  .ok(res => res.status >= 200 && res.status < 400)
  .then(res => {
    console.log(res.status)
    console.log(res.headers['location'])
  })

Reference documentation: Following Redirects: SuperAgent Documentation Error Handling: SuperAgent Documentation

thx, I'll try later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants