Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/chooz/common/config/CommonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/chooz/common/dev/DataInitConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class ApplicationControllerAdvice {

@ExceptionHandler(BadRequestException.class)
public ResponseEntity<ErrorResponse> 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<ErrorResponse> handle(UnauthorizedException e) {
ErrorResponse response = new ErrorResponse(e.getErrorCode());
ErrorResponse response = ErrorResponse.of(e.getErrorCode());
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.body(response);
}
Expand All @@ -50,7 +50,7 @@ public ResponseEntity<ErrorResponse> handle(UnauthorizedException e) {
public ResponseEntity<ErrorResponse> invalidArgument(Exception e) {
log.debug("invalidArgument: {}", e.getMessage());
return ResponseEntity.badRequest()
.body(new ErrorResponse(ErrorCode.INVALID_ARGUMENT));
.body(ErrorResponse.of(ErrorCode.INVALID_ARGUMENT));
}

@ExceptionHandler({
Expand All @@ -61,19 +61,19 @@ public ResponseEntity<ErrorResponse> invalidArgument(Exception e) {
public ResponseEntity<ErrorResponse> 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<ErrorResponse> 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<ErrorResponse> 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)
Expand All @@ -83,6 +83,6 @@ public ResponseEntity<ErrorResponse> 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));
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/chooz/common/exception/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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));

Expand All @@ -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));

Expand Down