Skip to content

Commit 27e6838

Browse files
committed
refactor: 예외 메시지 포함
1 parent 984bec6 commit 27e6838

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.oronaminc.join.global.exception;
22

3+
import com.oronaminc.join.global.util.StringUtil;
4+
import java.text.MessageFormat;
35
import lombok.AllArgsConstructor;
46
import lombok.Getter;
57

@@ -8,5 +10,19 @@
810
public class ErrorException extends RuntimeException {
911

1012
private final ErrorCode errorCode;
13+
private final String errorMessage;
1114

12-
}
15+
public ErrorException(ErrorCode errorCode) {
16+
this(errorCode, null);
17+
}
18+
19+
public static ErrorException of(ErrorCode errorCode, String message, Object... args) {
20+
String errorMessage = createMessage(message, args);
21+
return new ErrorException(errorCode, errorMessage);
22+
}
23+
24+
public String createMessage(String message, Object... args) {
25+
return StringUtil.format(message, args);
26+
}
27+
28+
}

src/main/java/com/oronaminc/join/global/exception/ExceptionAdvice.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ExceptionAdvice {
1818
public ResponseEntity<ErrorResponse> handleErrorException(ErrorException ex) {
1919
ErrorCode errorCode = ex.getErrorCode();
2020

21-
log.error(errorCode.getMessage(), ex);
21+
log.error("ErrorCode: {}, ErrorMessage: {}", ex.getErrorCode(), ex.getErrorMessage());
2222

2323
HttpStatus httpStatus = switch (errorCode.getErrorStatus()) {
2424
case NOT_FOUND -> HttpStatus.NOT_FOUND;

src/main/java/com/oronaminc/join/question/service/QuestionService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public Question update(Long memberId, Long roomId, Long questionId, QuestionRequ
8181

8282
// 참여자가 아님
8383
if (!participantReader.existsByRoomIdAndMemberId(roomId, memberId)) {
84-
throw new ErrorException(ErrorCode.NOT_FOUND_PARTICIPANT);
84+
throw ErrorException.of(ErrorCode.NOT_FOUND_PARTICIPANT,
85+
"{}번 발표방에는 {}번 회원이 잠가 중이지 않습니다.", roomId, memberId);
8586
}
8687

8788
// 작성자가 아님

0 commit comments

Comments
 (0)