codestates / codestates/Subllet
[ERR] Axios error response Handling
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
### 어떤 에러인가요?
- Axios 요청 후 status 400 응답을 처리하지 못해 응답 데이터로 업데이트 해줘야 할 상태를 변경하지 못함
### 에러 메시지
```shell
Uncaught (in promise) Error: Request failed with status code 400
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.onloadend (xhr.js:66)
```
### 에러 핸들링 방법
- 에러 객체를 확인하면 쉽게 해결이 가능한 부분이었다. 에러 객체를 확인하는 방법은 catch로 받아온 error뒤에 response를 붙여주면 간단히 해결할 수 있다. console.log(error.response), dir, error 다 가능하다.
- 이렇게 처리하면 응답에 대한 처리를 더욱 명시적으로 할 수 있게 된다.
```js
console.log(err.response.data);
```
```shell
{data: 'Empty body', status: 400, statusText: 'Bad Request', headers: {…}, config: {…}, …}
config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …}
data: "Empty body"
headers: {content-length: '10', content-type: 'text/html; charset=utf-8'}
request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: true, upload: XMLHttpRequestUpload, …}
status: 400
statusText: "Bad Request"
```
### 에러 핸들링을 위해 참고한 레퍼런스 링크
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.