codestates / codestates/BanThing

[Error Handling] joinroom roomsId에러

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

Description

### 어떤 에러인가요?
![image](https://user-images.githubusercontent.com/54207332/155267557-c8f2bb12-ee01-491e-b821-11bc9b145686.png)

- 에러 메시지
```
xhr.js?1a5c:210 POST http://localhost:3001/main 500 (Internal Server Error)
Error: Request failed with status code 500
at createError (createError.js?770c:16)
at settle (settle.js?8768:17)
at XMLHttpRequest.onloadend (xhr.js?1a5c:66)
```
![image](https://user-images.githubusercontent.com/54207332/155267825-265fd2a0-d5b7-41bf-9951-3c8c6ce85504.png)
![image](https://user-images.githubusercontent.com/54207332/155267867-9955c99f-f014-46ec-a7e3-922e1adc895d.png)
log에 roomsId를 찍어보니 0번이 나온다. 하지만 이건 이상하다
![image](https://user-images.githubusercontent.com/54207332/155267978-5194ef10-ed77-4ac1-9a57-aef2bb4317a3.png)
DB에는 0번째 방이 없기 때문이다.

### 에러 핸들링 방법
- roomsId가 0이 아닐때만 post요청을 해주었다.
```
useEffect(() => {
const getPosts = async () => {
try {
if (roomsId !== 0) {
const response: AxiosResponse = await axios.post(
`http://${process.env.NEXT_PUBLIC_SERVER_ENDPOINT}/main`,
{
id: roomsId,
},
);
setData(response.data);
}
} catch (e) {
console.log(e);
}
};
getPosts();
}, [roomsId]);
```

### 에러 핸들링을 위해 참고한 레퍼런스 링크
- Memory-It 의 Error Handling 예시입니다.
[링크](https://github.com/codestates/Memory-It/issues/205)

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.