22
33import jakarta .validation .Valid ;
44import lombok .RequiredArgsConstructor ;
5+ import org .springframework .http .HttpStatus ;
56import org .springframework .http .ResponseEntity ;
67import org .springframework .web .bind .annotation .*;
78import pawparazzi .back .comment .dto .request .ReplyRequestDto ;
1314import pawparazzi .back .comment .service .ReplyService ;
1415import pawparazzi .back .security .util .JwtUtil ;
1516
17+ import io .jsonwebtoken .JwtException ;
1618
1719import java .util .Map ;
1820
@@ -33,10 +35,13 @@ public ResponseEntity<ReplyResponseDto> createReply(
3335 @ PathVariable Long commentId ,
3436 @ RequestHeader ("Authorization" ) String token ,
3537 @ RequestBody @ Valid ReplyRequestDto requestDto ) {
36-
37- Long memberId = jwtUtil .extractMemberId (token .replace ("Bearer " , "" ));
38- ReplyResponseDto response = replyService .createReply (commentId , memberId , requestDto );
39- return ResponseEntity .ok (response );
38+ try {
39+ Long memberId = jwtUtil .extractMemberId (token .replace ("Bearer " , "" ));
40+ ReplyResponseDto response = replyService .createReply (commentId , memberId , requestDto );
41+ return ResponseEntity .ok (response );
42+ } catch (JwtException e ) {
43+ return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
44+ }
4045 }
4146
4247 /**
@@ -47,11 +52,14 @@ public ResponseEntity<ReplyResponseDto> updateReply(
4752 @ PathVariable Long replyId ,
4853 @ RequestHeader ("Authorization" ) String token ,
4954 @ RequestBody Map <String , String > request ) {
50-
51- Long memberId = jwtUtil .extractMemberId (token .replace ("Bearer " , "" ));
52- String content = request .get ("content" );
53- ReplyResponseDto response = replyService .updateReply (replyId , memberId , content );
54- return ResponseEntity .ok (response );
55+ try {
56+ Long memberId = jwtUtil .extractMemberId (token .replace ("Bearer " , "" ));
57+ String content = request .get ("content" );
58+ ReplyResponseDto response = replyService .updateReply (replyId , memberId , content );
59+ return ResponseEntity .ok (response );
60+ } catch (JwtException e ) {
61+ return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
62+ }
5563 }
5664
5765 /**
@@ -61,11 +69,13 @@ public ResponseEntity<ReplyResponseDto> updateReply(
6169 public ResponseEntity <Map <String , String >> deleteReply (
6270 @ PathVariable Long replyId ,
6371 @ RequestHeader ("Authorization" ) String token ) {
64-
65- Long memberId = jwtUtil .extractMemberId (token .replace ("Bearer " , "" ));
66- replyService .deleteReply (replyId , memberId );
67-
68- return ResponseEntity .ok (Map .of ("message" , "대댓글이 삭제되었습니다." ));
72+ try {
73+ Long memberId = jwtUtil .extractMemberId (token .replace ("Bearer " , "" ));
74+ replyService .deleteReply (replyId , memberId );
75+ return ResponseEntity .ok (Map .of ("message" , "대댓글이 삭제되었습니다." ));
76+ } catch (JwtException e ) {
77+ return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
78+ }
6979 }
7080
7181 /**
@@ -76,19 +86,20 @@ public ResponseEntity<ReplyListResponseDto> getReplies(@PathVariable Long commen
7686 return ResponseEntity .ok (replyService .getRepliesByComment (commentId ));
7787 }
7888
79-
8089 /**
8190 * 대댓글 좋아요 등록/삭제 (토글)
8291 */
8392 @ PostMapping ("/{replyId}/like" )
8493 public ResponseEntity <ReplyLikeResponseDto > toggleReplyLike (
8594 @ PathVariable Long replyId ,
8695 @ RequestHeader ("Authorization" ) String token ) {
87-
88- Long memberId = jwtUtil .extractMemberId (token .replace ("Bearer " , "" ));
89- ReplyLikeResponseDto response = replyLikeService .toggleReplyLike (replyId , memberId );
90-
91- return ResponseEntity .ok (response );
96+ try {
97+ Long memberId = jwtUtil .extractMemberId (token .replace ("Bearer " , "" ));
98+ ReplyLikeResponseDto response = replyLikeService .toggleReplyLike (replyId , memberId );
99+ return ResponseEntity .ok (response );
100+ } catch (JwtException e ) {
101+ return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).build ();
102+ }
92103 }
93104
94105 /**
0 commit comments