frontend

[Axios] Axios의 catch()문에서 Status Code 받기

sup2is 2019. 4. 15. 11:23

 

 

 

catch(error =>) {

  console.log(error)

}

 

로 찍으면

 

 

Error: Request failed with status code 422
    at createError (app.js:6765)
    at settle (app.js:29489)
    at XMLHttpRequest.handleLoad (app.js:6600)

 

단순 string만 반환하는데

 

return 된 object를 받고 싶으면

 

 

axios.post('/formulas/create', {
	name: "",
	parts: ""
})
.then(response => { 
	console.log(response)
})
.catch(error => {
    console.log(error.response)
});

 

 

 

console.log(error.response) 로 받으면 된다

 

 

출처 : https://github.com/axios/axios/issues/960