From 57a9575adad8fbf3096537789c31379fad4fc9cd Mon Sep 17 00:00:00 2001 From: smg0725 Date: Sat, 3 Aug 2024 19:19:33 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[CHORE]=20=EC=BB=A8=EB=B2=A4=EC=85=98=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/handler/ErrorHandler.java | 109 +++++++++--------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/tiki/server/common/handler/ErrorHandler.java b/src/main/java/com/tiki/server/common/handler/ErrorHandler.java index 571818e8..6034d0ec 100644 --- a/src/main/java/com/tiki/server/common/handler/ErrorHandler.java +++ b/src/main/java/com/tiki/server/common/handler/ErrorHandler.java @@ -24,67 +24,66 @@ @RestControllerAdvice public class ErrorHandler { - @ExceptionHandler(MemberException.class) - public ResponseEntity memberException(MemberException exception) { - log.error(exception.getMessage()); - val errorCode = exception.getErrorCode(); - return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); - } + @ExceptionHandler(MemberException.class) + public ResponseEntity memberException(MemberException exception) { + log.error(exception.getMessage()); + val errorCode = exception.getErrorCode(); + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } - @ExceptionHandler(TeamException.class) - public ResponseEntity teamException(TeamException exception) { - log.error(exception.getMessage()); - val errorCode = exception.getErrorCode(); - return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); - } + @ExceptionHandler(TeamException.class) + public ResponseEntity teamException(TeamException exception) { + log.error(exception.getMessage()); + val errorCode = exception.getErrorCode(); + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } - @ExceptionHandler(MemberTeamManagerException.class) - public ResponseEntity memberTeamManagerException(MemberTeamManagerException exception) { - log.error(exception.getMessage()); - val errorCode = exception.getErrorCode(); - return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); - } + @ExceptionHandler(MemberTeamManagerException.class) + public ResponseEntity memberTeamManagerException(MemberTeamManagerException exception) { + log.error(exception.getMessage()); + val errorCode = exception.getErrorCode(); + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } - @ExceptionHandler(TimeBlockException.class) - public ResponseEntity timeBlockException(TimeBlockException exception) { - log.error(exception.getMessage()); - val errorCode = exception.getErrorCode(); - return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); - } + @ExceptionHandler(TimeBlockException.class) + public ResponseEntity timeBlockException(TimeBlockException exception) { + log.error(exception.getMessage()); + val errorCode = exception.getErrorCode(); + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } - @ExceptionHandler(DocumentException.class) - public ResponseEntity documentException(DocumentException exception) { - log.error(exception.getMessage()); - val errorCode = exception.getErrorCode(); - return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); - } + @ExceptionHandler(DocumentException.class) + public ResponseEntity documentException(DocumentException exception) { + log.error(exception.getMessage()); + val errorCode = exception.getErrorCode(); + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } - @ExceptionHandler(ExternalException.class) - public ResponseEntity externalException(ExternalException exception) { - log.error(exception.getMessage()); - val errorCode = exception.getErrorCode(); - return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); - } + @ExceptionHandler(ExternalException.class) + public ResponseEntity externalException(ExternalException exception) { + log.error(exception.getMessage()); + val errorCode = exception.getErrorCode(); + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } - @ExceptionHandler(MailException.class) - public ResponseEntity MailException(MailException exception) { - log.error(exception.getMessage()); - val errorCode = exception.getErrorCode(); - return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); - } + @ExceptionHandler(MailException.class) + public ResponseEntity MailException(MailException exception) { + log.error(exception.getMessage()); + val errorCode = exception.getErrorCode(); + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } - @ExceptionHandler(AuthException.class) - public ResponseEntity AuthException(AuthException exception) { - log.error(exception.getMessage()); - val errorCode = exception.getErrorCode(); - return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); - } + @ExceptionHandler(AuthException.class) + public ResponseEntity AuthException(AuthException exception) { + log.error(exception.getMessage()); + val errorCode = exception.getErrorCode(); + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } - @ExceptionHandler(Exception.class) - public ResponseEntity Exception(Exception exception) { - log.info("here!!"); - log.error(exception.getMessage()); - val errorCode = UNCAUGHT_SERVER_EXCEPTION; - return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); - } + @ExceptionHandler(Exception.class) + public ResponseEntity Exception(Exception exception) { + log.error(exception.getMessage()); + val errorCode = UNCAUGHT_SERVER_EXCEPTION; + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } } From b49f4fba69580b99c955ab73277dd1e273c79e7f Mon Sep 17 00:00:00 2001 From: smg0725 Date: Sat, 3 Aug 2024 19:20:11 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[CHORE]=20=EB=A6=AC=EC=9D=B4=EC=8A=88?= =?UTF-8?q?=EC=8B=9C=20=EB=A6=AC=ED=94=84=EB=A0=88=EC=89=AC=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=EC=9D=84=20=EC=BF=A0=ED=82=A4=EB=A1=9C=20=EB=B0=9B?= =?UTF-8?q?=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tiki/server/auth/controller/AuthController.java | 6 ++++-- .../java/com/tiki/server/auth/service/AuthService.java | 9 +++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/tiki/server/auth/controller/AuthController.java b/src/main/java/com/tiki/server/auth/controller/AuthController.java index 82b53ce6..f903fa9b 100644 --- a/src/main/java/com/tiki/server/auth/controller/AuthController.java +++ b/src/main/java/com/tiki/server/auth/controller/AuthController.java @@ -38,8 +38,10 @@ public ResponseEntity> signIn( } @GetMapping("/reissue") - public ResponseEntity> reissue(HttpServletRequest httpServletRequest) { - val response = authService.reissueToken(httpServletRequest); + public ResponseEntity> reissue( + @CookieValue(name = "refreshToken", required = false)String refreshToken + ) { + val response = authService.reissueToken(refreshToken); return ResponseEntity.created(UriGenerator.getUri("/")) .body(SuccessResponse.success(SUCCESS_REISSUE_ACCESS_TOKEN.getMessage(), response)); } diff --git a/src/main/java/com/tiki/server/auth/service/AuthService.java b/src/main/java/com/tiki/server/auth/service/AuthService.java index cdb775a7..d309d6f3 100644 --- a/src/main/java/com/tiki/server/auth/service/AuthService.java +++ b/src/main/java/com/tiki/server/auth/service/AuthService.java @@ -11,7 +11,6 @@ import com.tiki.server.member.adapter.MemberFinder; import com.tiki.server.member.entity.Member; import com.tiki.server.member.exception.MemberException; -import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; @@ -54,9 +53,7 @@ public SignInGetResponse login(LoginRequest request, HttpServletResponse respons return SignInGetResponse.from(accessToken, refreshToken); } - public ReissueGetResponse reissueToken(HttpServletRequest request) { - System.out.println("1"); - val refreshToken = jwtProvider.getTokenFromRequest(request); + public ReissueGetResponse reissueToken(String refreshToken) { checkTokenEmpty(refreshToken); val memberId = jwtProvider.getUserFromJwt(refreshToken); val token = tokenFinder.findById(memberId); @@ -70,8 +67,8 @@ private Member checkMemberEmpty(LoginRequest request) { return memberFinder.findByEmail(request.email()).orElseThrow(() -> new MemberException(INVALID_MEMBER)); } - private void checkTokenEmpty(String token){ - if(StringUtils.isEmpty(token)){ + private void checkTokenEmpty(String token) { + if (StringUtils.isEmpty(token)) { throw new AuthException(EMPTY_JWT); } } From 018b70b5afefd80adfe46781ecb6d3ef8ba0bdc4 Mon Sep 17 00:00:00 2001 From: smg0725 Date: Sun, 4 Aug 2024 01:21:55 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[CHORE]=20required=20=EC=86=8D=EC=84=B1=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tiki/server/auth/controller/AuthController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tiki/server/auth/controller/AuthController.java b/src/main/java/com/tiki/server/auth/controller/AuthController.java index f903fa9b..f3a44e7f 100644 --- a/src/main/java/com/tiki/server/auth/controller/AuthController.java +++ b/src/main/java/com/tiki/server/auth/controller/AuthController.java @@ -1,4 +1,5 @@ package com.tiki.server.auth.controller; + import com.tiki.server.auth.dto.request.LoginRequest; import com.tiki.server.auth.dto.response.ReissueGetResponse; import com.tiki.server.common.dto.SuccessResponse; @@ -39,7 +40,7 @@ public ResponseEntity> signIn( @GetMapping("/reissue") public ResponseEntity> reissue( - @CookieValue(name = "refreshToken", required = false)String refreshToken + @CookieValue(name = "refreshToken") String refreshToken ) { val response = authService.reissueToken(refreshToken); return ResponseEntity.created(UriGenerator.getUri("/"))