codestates / codestates/BanThing

[Error Handling] 'Content-Type': 'application/json' 가 작동하지 않는 현상

Open
#145 0 comments 0 reactions 1 assignee Claimed by @slight-snow View on GitHub
client error solved
Dominant language
TypeScript
Stars
0
Forks
2
PR merge metrics
No merged PRs in 30d

Description

### 어떤 에러인가요?
- axios POST 요청을 보내는 과정에서 `'Content-Type': 'application/json'`, `withCredentials: true,` 를 넣어줬으나
밑에 붉은 줄이 나타나며 axios 파라미터상 적합하지 않다는 경고 문구가 나타났습니다.

### 에러 핸들링 방법
- 구글링을 해보니 `'Content-Type': 'application/json'` 은 `{config}` 의 headers 내에 작성한다고 합니다.
JavaScript 때 별다른 에러가 나타나지 않아 headers 밖에 작성하는 것이 맞다고 생각했습니다만,
JavaScript 특성상 코드에 대해 엄격하지 않기 때문에 넘어갈 수 있었던 것 같습니다.
```javascript
const handleLogout = () => {
axios
.post(
`http://${process.env.NEXT_PUBLIC_SERVER_ENDPOINT}/users/logout`,
{},
{
headers: {
Authorization: `Bearer ${prop.accessToken}`,
'Content-Type': 'application/json',
},
withCredentials: true,
},
)
```
- 위와 같이 headers 내에 작성해주니 에러 없이 정상 작동했습니다.

 

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.