Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status code 300 return error in catch block when using axios

When i am making a http call with axios it goes in catch block with error My requirement is to handle the 300 response in then block it should not got to catch, how can i achieve that through axios

like image 780
Mukesh Kumar Avatar asked Jul 20 '26 23:07

Mukesh Kumar


1 Answers

I think you have multiple choices. You can either extract your code from then callback into function - and call it in error handler when status code is 300.

You could also try this option from axios, to reject the promise only when the status code is > 301.

axios.get('/user/12345', {
  validateStatus: function (status) {
    return status <= 300; // Reject only if the status code is greater than 300
  }
})
like image 78
Borys Kupar Avatar answered Jul 23 '26 13:07

Borys Kupar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!