-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 투표 생성 시 존재하지 않는 데이터를 요구한 경우 예외 처리 * feat: 중복 투표를 진행하는 경우 예외 처리 * feat: 투표가 이미 종료된 게시글에 투표하려는 경우 예외 처리 * style: 로직 순서 변경 * feat: 존재하지 않는 데이터 요청 시 예외 처리 * feat: 카테고리가 'CASUAL'인 게시글에서 투표를 수정하려는 경우 예외 처리 * feat: 해당 게시글에서 투표한 기록이 없을 때 투표를 수정하려는 경우 예외 처리
- Loading branch information
Showing
7 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/balancetalk/global/exception/BalanceTalkException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package balancetalk.global.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BalanceTalkException extends RuntimeException { | ||
|
||
private final ErrorCode errorCode; | ||
|
||
public BalanceTalkException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package balancetalk.global.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ErrorCode { | ||
// 400 | ||
MISMATCHED_BALANCE_OPTION(BAD_REQUEST, "선택한 선택지는 다른 게시글에 속해 있습니다."), | ||
EXPIRED_POST_DEADLINE(BAD_REQUEST, "투표가 이미 종료된 게시글입니다."), | ||
UNMODIFIABLE_VOTE(BAD_REQUEST, "투표 수정이 불가능한 게시글입니다."), | ||
|
||
// 404 | ||
NOT_FOUND_POST(NOT_FOUND, "존재하지 않는 게시글입니다."), | ||
NOT_FOUND_BALANCE_OPTION(NOT_FOUND, "존재하지 않는 선택지입니다."), | ||
NOT_FOUND_MEMBER(NOT_FOUND, "존재하지 않는 회원입니다."), | ||
NOT_FOUND_VOTE(NOT_FOUND, "해당 게시글에서 투표한 기록이 존재하지 않습니다."), | ||
|
||
// 409 | ||
ALREADY_VOTE(CONFLICT, "투표는 한 번만 가능합니다."); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String message; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/balancetalk/global/exception/ErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package balancetalk.global.exception; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class ErrorResponse { | ||
|
||
private HttpStatus httpStatus; | ||
private String message; | ||
|
||
public static ErrorResponse from(ErrorCode errorCode) { | ||
return new ErrorResponse(errorCode.getHttpStatus(), errorCode.getMessage()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/balancetalk/global/exception/GlobalExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package balancetalk.global.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(BalanceTalkException.class) | ||
public ResponseEntity<ErrorResponse> handleBalanceTalkException(BalanceTalkException e) { | ||
ErrorResponse errorResponse = ErrorResponse.from(e.getErrorCode()); | ||
log.error("exception message = {}", e.getMessage()); | ||
return ResponseEntity.status(errorResponse.getHttpStatus()).body(errorResponse); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters