catch error 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: how to handle error axios js
axios.post("/api/end", {data : "xx"})
.then(({ data }) => {
})
.catch((err) => {
let message = typeof err.response !== "undefined" ? err.response.data.message : err.message;
console.warn("error", message);
});