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..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("dev") +@Profile({"dev", "local"}) @Component @RequiredArgsConstructor public class DataInitConfig { 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));