I'm using AXIOS with REACTjs
I want a functionality that if my first API(GET
) call returns Not Found
status code then I want to send the other call efficiently.
Although I'm getting some data through that .catch
method in form of Promise<pending>
.Please Help!!!
CodePudding user response:
Why don’t you add a conditional in the catch block to check the status?
For example:
axios.get('/first-call')
.then(resp => {
//handle successful response
})
.catch(error => {
if (error.response && error.response.status === 404) {
// make second API call
}
});