codestates / codestates/BanThing

[Error Handling] 로그인 되지 않은 상태에서 메인페이지 이용할 때 버그

Open
#164 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

### 어떤 에러인가요?
window.localStorage
- 에러 메시지
```
Unhandled Runtime Error
Error: Request failed with status code 401
```

### 에러 핸들링 방법
- 로그 아웃 상태에서 기존의 localStorage에러를 잡기 위해 사용하였던 조건문을 사용해보니
```
if (typeof window !== 'undefined' && window.localStorage) {
console.log(1);
}
```
![image](https://user-images.githubusercontent.com/54207332/155443263-c270f785-6a66-4ae8-b690-733c27025b7d.png)
로그가 찍히는 불상사가 있었다.
```
if (typeof window !== 'undefined' && localStorage.getItem('accessToken')) {
console.log(1);
}
```
아예 토큰 값이 없었을 때를 명시해주니 에러가 사라졌다.

### 에러 핸들링을 위해 참고한 레퍼런스 링크
- 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.