Answers for "how to get error code in axios"

7

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)
});
Posted by: Guest on May-30-2020
11

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)
     }
Posted by: Guest on May-24-2020
0

How can I get the status code from an http error in Axios?

axios.get('/foo')
  .catch(function (error) {
    if (error.response) {
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    }
  });
Posted by: Guest on July-05-2021

Code answers related to "how to get error code in axios"

Code answers related to "Javascript"

Browse Popular Code Answers by Language