File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 1
- import { useState } from 'react' ;
1
+ import { useContext , useState } from 'react' ;
2
+
3
+ import { UserContext } from '../contexts/UserProvider' ;
2
4
import { ERROR_MESSAGE } from '../constants/message' ;
3
5
import {
4
6
requestGetStudylog ,
@@ -7,17 +9,26 @@ import {
7
9
requestEditStudylog ,
8
10
} from '../service/requests' ;
9
11
import useMutation from './useMutation' ;
12
+ import ERROR_CODE from '../constants/errorCode' ;
10
13
11
14
const useStudylog = ( defaultValue ) => {
12
15
const [ response , setResponse ] = useState ( defaultValue ) ;
13
16
const [ error , setError ] = useState ( '' ) ;
14
17
18
+ const { onLogout } = useContext ( UserContext )
19
+
15
20
const onSuccess = ( data ) => {
16
21
setResponse ( data ) ;
22
+ setError ( '' ) ;
17
23
} ;
18
24
19
25
const onError = ( error ) => {
20
26
console . error ( error ) ;
27
+
28
+ if ( error . code === ERROR_CODE . EXPIRED_ACCESS_TOKEN ) {
29
+ onLogout ( ) ;
30
+ }
31
+
21
32
setError ( ERROR_MESSAGE [ error . code ] ?? ERROR_MESSAGE . DEFAULT ) ;
22
33
} ;
23
34
Original file line number Diff line number Diff line change @@ -14,12 +14,18 @@ import { UserContext } from '../../contexts/UserProvider';
14
14
const MainPage = ( ) => {
15
15
const { user } = useContext ( UserContext ) ;
16
16
const { accessToken } = user ;
17
- const { response : recentStudylogs , getAllData : fetchRecentStudylogs } = useStudylog ( [ ] ) ;
17
+ const { response : recentStudylogs , error : recentStudylogsError , getAllData : fetchRecentStudylogs } = useStudylog ( [ ] ) ;
18
18
19
19
useEffect ( ( ) => {
20
20
fetchRecentStudylogs ( { query : { type : 'searchParams' , data : 'size=3' } , accessToken } ) ;
21
21
} , [ accessToken ] ) ;
22
22
23
+ useEffect ( ( ) => {
24
+ if ( recentStudylogsError ) {
25
+ alert ( recentStudylogsError )
26
+ }
27
+ } , [ recentStudylogsError ] )
28
+
23
29
return (
24
30
< >
25
31
< BannerList bannerList = { bannerList } />
You can’t perform that action at this time.
0 commit comments