공부기록/웹 개발
post 에러 몇번대 에러인지 체크하는 방법
_우지
2022. 8. 7. 17:39
요청을 보냈을때 다음 처럼 몇번 status 의 에러를 가지는지로 모달의 띄워줘야하는 상황이였다.
409 번 에러라면 포인트를 확인해주세요 라는 모달을 띄워야했는데, 한번보도록 하자.
다음처럼 catch 문에서 error.response.status 를 통해서 해당 값이 몇번대의 에러인지 알 수 있었다.
.catch(function (error) {
// handle error
console.log(error);
if (error.response.status === 409) {
dispatcher(setCreatePointModalExcept({ value: true }));
}
출처자료
How can I get the status code from an HTTP error in Axios?
This may seem stupid, but I'm trying to get the error data when a request fails in Axios. axios .get('foo.example') .then((response) => {}) .catch((error) => { console.log(error); /...
stackoverflow.com