Commit 03bffb1 1 parent 311b479 commit 03bffb1 Copy full SHA for 03bffb1
File tree 2 files changed +20
-11
lines changed
2 files changed +20
-11
lines changed Original file line number Diff line number Diff line change 6
6
REACTION_TYPE ,
7
7
ReactionsResponse ,
8
8
} from "./response" ;
9
+ import { isAxiosError } from "axios" ;
9
10
10
- interface Response < T > {
11
+ export interface Response < T > {
11
12
status : number ;
12
13
data : T ;
13
14
timestamp : Date ;
@@ -46,14 +47,20 @@ export const postReactions = async (
46
47
reactionType : keyof typeof REACTION_TYPE ,
47
48
boardId : number
48
49
) => {
49
- const { data } = await client . post < Response < ReactionsResponse > > (
50
- `/reactions` ,
51
- {
52
- reactionType,
53
- boardId,
50
+ try {
51
+ const { data } = await client . post < Response < ReactionsResponse > > (
52
+ `/reactions` ,
53
+ {
54
+ reactionType,
55
+ boardId,
56
+ }
57
+ ) ;
58
+ return data ;
59
+ } catch ( err ) {
60
+ if ( isAxiosError ( err ) ) {
61
+ return err . response ?. data ;
54
62
}
55
- ) ;
56
- return data ;
63
+ }
57
64
} ;
58
65
59
66
export const getRandomDaybooks = async ( ) => {
Original file line number Diff line number Diff line change 1
1
import styled from "@emotion/styled" ;
2
2
import getFontStyle from "@theme/font/getFontSize" ;
3
3
import { colors } from "@theme" ;
4
- import { postReactions } from "@api" ;
4
+ import { Response , postReactions } from "@api" ;
5
5
import { REACTION_TYPE , ReactionObject } from "@api/response" ;
6
6
import { getReactionCount } from "@utils/getReactionCount" ;
7
7
@@ -13,10 +13,12 @@ interface DetailCardFooterProps {
13
13
const DetailCardFooter = ( { boardId, reactions } : DetailCardFooterProps ) => {
14
14
15
15
const post = async ( reactionType : keyof typeof REACTION_TYPE , id : number ) => {
16
- const res = await postReactions ( reactionType , id ) ;
16
+ const res = ( await postReactions ( reactionType , id ) ) as Response < unknown > ;
17
17
if ( res . status === 409 ) {
18
- alert ( "이미 공감한 글입니다!" )
18
+ window . alert ( '이미 공감한 글입니다!' )
19
+ return ;
19
20
}
21
+ window . location . reload ( ) ;
20
22
}
21
23
22
24
const { ADMIRE , GREAT , MOVING } = getReactionCount ( reactions ) ;
You can’t perform that action at this time.
0 commit comments