how to get error status code axios code example
Example 1: get json data when we get error code in axios
axios.post('/formulas/create', {
name: "",
parts: ""
})
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error.response)
});
Example 2: axios try catch get error status cocxe
try {
await axios.get('/bad-call')
} catch (error) {
const err = error as AxiosError
if (err.response) {
console.log(err.response.status)
console.log(err.response.data)
}
this.handleAxiosError(error)
}
Example 3: axios error
axios.get('/api/xyz/abcd')
.catch(function (error) {
if (error.response) {
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
console.log(error.request);
} else {
console.log('Error', error.message);
}
});
Example 4: axios how to get error response
axios.post('/formulas/create', {
name: "",
parts: ""
})
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error.response)
});
Example 5: axios get status code
axios.get('/foo')
.catch(function (error) {
if (error.response) {
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
}
});