axios({ url: `$requestUrl` }).then(response => { callback(parentId, id); }).catch(response => { console.log(response); errorCallback(response); });
axios 호출시 catch 인자로 들어오는 것은 데이터가 아니라 error 자체이다. console.log 찍어보면 다음과 같다.
Error: Request failed with status code 404
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:59)
그래서 서버에서 내려준 데이터를 쓰고 싶을 때는 다음과 같이 써야한다. 어찌 생각하면 catch(e)가 당연한..
catch(error => { errorCallback(error.response); })
더 자세한 axios 에러 핸들링은 아래에서 확인할 수 있다.
github.com/axios/axios#handling-errors
axios/axios
Promise based HTTP client for the browser and node.js - axios/axios
github.com
'삽질북' 카테고리의 다른 글
mybatis mapper 오류 (0) | 2021.11.24 |
---|---|
node는 있는데 npm은 없는 경우.. (0) | 2021.05.09 |
error: SchemaError(io.k8s.api.core.v1.CinderVolumeSource): invalid object doesn't have additional properties (0) | 2021.04.30 |