From bd8550a2bae07d86bda7f2ec728b3109f4115e65 Mon Sep 17 00:00:00 2001 From: wlsh44 Date: Thu, 11 Sep 2025 17:24:00 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=EC=97=90=EB=9F=AC=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/ApplicationControllerAdvice.java | 14 +++++++------- .../com/chooz/common/exception/ErrorResponse.java | 6 +++++- .../auth/presentation/AuthControllerTest.java | 6 +++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/chooz/common/exception/ApplicationControllerAdvice.java b/src/main/java/com/chooz/common/exception/ApplicationControllerAdvice.java index 00dc6dc1..9f4cce4c 100644 --- a/src/main/java/com/chooz/common/exception/ApplicationControllerAdvice.java +++ b/src/main/java/com/chooz/common/exception/ApplicationControllerAdvice.java @@ -29,14 +29,14 @@ public class ApplicationControllerAdvice { @ExceptionHandler(BadRequestException.class) public ResponseEntity handle(BadRequestException e) { - ErrorResponse response = new ErrorResponse(e.getErrorCode()); + ErrorResponse response = ErrorResponse.of(e.getErrorCode()); return ResponseEntity.badRequest() .body(response); } @ExceptionHandler(UnauthorizedException.class) public ResponseEntity handle(UnauthorizedException e) { - ErrorResponse response = new ErrorResponse(e.getErrorCode()); + ErrorResponse response = ErrorResponse.of(e.getErrorCode()); return ResponseEntity.status(HttpStatus.UNAUTHORIZED) .body(response); } @@ -50,7 +50,7 @@ public ResponseEntity handle(UnauthorizedException e) { public ResponseEntity invalidArgument(Exception e) { log.debug("invalidArgument: {}", e.getMessage()); return ResponseEntity.badRequest() - .body(new ErrorResponse(ErrorCode.INVALID_ARGUMENT)); + .body(ErrorResponse.of(ErrorCode.INVALID_ARGUMENT)); } @ExceptionHandler({ @@ -61,19 +61,19 @@ public ResponseEntity invalidArgument(Exception e) { public ResponseEntity notFound(Exception e) { log.debug("notFound: {}", e.getMessage()); return ResponseEntity.status(HttpStatus.NOT_FOUND) - .body(new ErrorResponse(ErrorCode.NOT_FOUND)); + .body(ErrorResponse.of(ErrorCode.NOT_FOUND)); } @ExceptionHandler(AuthenticationException.class) public ResponseEntity handle(AuthenticationException e) { log.debug(e.getMessage()); - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new ErrorResponse(ErrorCode.INVALID_TOKEN)); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ErrorResponse.of(ErrorCode.INVALID_TOKEN)); } @ExceptionHandler(ForbiddenException.class) public ResponseEntity handle(ForbiddenException e) { log.debug(e.getMessage()); - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ErrorResponse(ErrorCode.FORBIDDEN)); + return ResponseEntity.status(HttpStatus.FORBIDDEN).body(ErrorResponse.of(ErrorCode.FORBIDDEN)); } @ExceptionHandler(Exception.class) @@ -83,6 +83,6 @@ public ResponseEntity handle(Exception e, WebRequest webRequest) discordMessageSender.sendDiscordAlarm(e, webRequest); } return ResponseEntity.internalServerError() - .body(new ErrorResponse(ErrorCode.INTERNAL_SERVER_ERROR)); + .body(ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR)); } } diff --git a/src/main/java/com/chooz/common/exception/ErrorResponse.java b/src/main/java/com/chooz/common/exception/ErrorResponse.java index 34eda0f7..5b527892 100644 --- a/src/main/java/com/chooz/common/exception/ErrorResponse.java +++ b/src/main/java/com/chooz/common/exception/ErrorResponse.java @@ -1,4 +1,8 @@ package com.chooz.common.exception; -public record ErrorResponse(ErrorCode errorCode) { +public record ErrorResponse(ErrorCode errorCode, String message) { + + public static ErrorResponse of(ErrorCode errorCode) { + return new ErrorResponse(errorCode, errorCode.getMessage()); + } } diff --git a/src/test/java/com/chooz/auth/presentation/AuthControllerTest.java b/src/test/java/com/chooz/auth/presentation/AuthControllerTest.java index d82c7eee..a0bba57d 100644 --- a/src/test/java/com/chooz/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/chooz/auth/presentation/AuthControllerTest.java @@ -119,7 +119,7 @@ void reissue() throws Exception { @DisplayName("토큰 재발급 - 리프레시 토큰 헤더 없는 경우") void reissue_invalidRefreshTokenHeader() throws Exception { //given - ErrorResponse response = new ErrorResponse(ErrorCode.INVALID_REFRESH_TOKEN_HEADER); + ErrorResponse response = ErrorResponse.of(ErrorCode.INVALID_REFRESH_TOKEN_HEADER); //when then mockMvc.perform(post("/auth/reissue")) @@ -131,7 +131,7 @@ void reissue_invalidRefreshTokenHeader() throws Exception { @DisplayName("토큰 재발급 - 리프레시 토큰 헤더가 db에 없는 경우") void reissue_refreshTokenNotFound() throws Exception { //given - ErrorResponse response = new ErrorResponse(ErrorCode.REFRESH_TOKEN_NOT_FOUND); + ErrorResponse response = ErrorResponse.of(ErrorCode.REFRESH_TOKEN_NOT_FOUND); given(authService.reissue(anyString())) .willThrow(new BadRequestException(ErrorCode.REFRESH_TOKEN_NOT_FOUND)); @@ -146,7 +146,7 @@ void reissue_refreshTokenNotFound() throws Exception { @DisplayName("토큰 재발급 - 리프레시 토큰 헤더가 db에 있는 값과 일치하지 않은 경우") void reissue_refreshTokenMismatched() throws Exception { //given - ErrorResponse response = new ErrorResponse(ErrorCode.REFRESH_TOKEN_MISMATCHED); + ErrorResponse response = ErrorResponse.of(ErrorCode.REFRESH_TOKEN_MISMATCHED); given(authService.reissue(anyString())) .willThrow(new BadRequestException(ErrorCode.REFRESH_TOKEN_MISMATCHED)); From 004d3a89f67c4a2c540c578f0419a85c177ef478 Mon Sep 17 00:00:00 2001 From: wlsh44 Date: Thu, 11 Sep 2025 17:45:54 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=EC=8A=A4=EC=BC=80=EC=A4=84=EB=A7=81?= =?UTF-8?q?=20=EC=95=88=EB=90=98=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/chooz/common/config/CommonConfig.java | 2 ++ src/main/java/com/chooz/common/dev/DataInitConfig.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chooz/common/config/CommonConfig.java b/src/main/java/com/chooz/common/config/CommonConfig.java index dc1e4f1c..d6758045 100644 --- a/src/main/java/com/chooz/common/config/CommonConfig.java +++ b/src/main/java/com/chooz/common/config/CommonConfig.java @@ -3,10 +3,12 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; import java.time.Clock; @Configuration +@EnableScheduling @ConfigurationPropertiesScan(basePackages = "com.chooz") public class CommonConfig { diff --git a/src/main/java/com/chooz/common/dev/DataInitConfig.java b/src/main/java/com/chooz/common/dev/DataInitConfig.java index d5332f58..b2eea114 100644 --- a/src/main/java/com/chooz/common/dev/DataInitConfig.java +++ b/src/main/java/com/chooz/common/dev/DataInitConfig.java @@ -5,7 +5,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -@Profile("dev") +@Profile({"!prod", "!test"}) @Component @RequiredArgsConstructor public class DataInitConfig { From 79bfadac8997d894178579ffaa9c040f1909afb3 Mon Sep 17 00:00:00 2001 From: wlsh44 Date: Thu, 11 Sep 2025 18:00:44 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=EA=B0=9C=EB=B0=9C=EC=9A=A9=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B4=88=EA=B8=B0=ED=99=94=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/chooz/common/dev/DataInitConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chooz/common/dev/DataInitConfig.java b/src/main/java/com/chooz/common/dev/DataInitConfig.java index b2eea114..f6418ca2 100644 --- a/src/main/java/com/chooz/common/dev/DataInitConfig.java +++ b/src/main/java/com/chooz/common/dev/DataInitConfig.java @@ -5,7 +5,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -@Profile({"!prod", "!test"}) +@Profile({"dev", "local"}) @Component @RequiredArgsConstructor public class DataInitConfig {