From b64ea43e0c6d0e4ecd45d1c76d6d3444f607f331 Mon Sep 17 00:00:00 2001 From: limkanghyun Date: Tue, 15 Jul 2025 11:42:30 +0900 Subject: [PATCH 1/6] =?UTF-8?q?:sparkles:=20feat:=20=EA=B8=80=EB=A1=9C?= =?UTF-8?q?=EB=B2=8C=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=ED=95=B8?= =?UTF-8?q?=EB=93=A4=EB=9F=AC=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20validatio?= =?UTF-8?q?n=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/CustomException.java | 13 ++++- .../exception/errorcode/AuthErrorCode.java | 25 +++++++++ .../exception/errorcode/CommonErrorCode.java | 20 +++++++ .../global/exception/errorcode/ErrorCode.java | 13 +++++ .../errorcode/QuestionErrorCode.java | 19 +++++++ .../exception/errorcode/QuizErrorCode.java | 22 ++++++++ .../exception/errorcode/RoomErrorCode.java | 21 +++++++ .../exception/errorcode/UserErrorCode.java | 22 ++++++++ .../handler/GlobalExceptionHandler.java | 56 +++++++++++++++++++ .../exception/response/ErrorResponse.java | 13 +++++ 10 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/java/io/f1/backend/global/exception/errorcode/AuthErrorCode.java create mode 100644 backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java create mode 100644 backend/src/main/java/io/f1/backend/global/exception/errorcode/ErrorCode.java create mode 100644 backend/src/main/java/io/f1/backend/global/exception/errorcode/QuestionErrorCode.java create mode 100644 backend/src/main/java/io/f1/backend/global/exception/errorcode/QuizErrorCode.java create mode 100644 backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java create mode 100644 backend/src/main/java/io/f1/backend/global/exception/errorcode/UserErrorCode.java create mode 100644 backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java create mode 100644 backend/src/main/java/io/f1/backend/global/exception/response/ErrorResponse.java diff --git a/backend/src/main/java/io/f1/backend/global/exception/CustomException.java b/backend/src/main/java/io/f1/backend/global/exception/CustomException.java index 2cd6202f..a2a14cdd 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/CustomException.java +++ b/backend/src/main/java/io/f1/backend/global/exception/CustomException.java @@ -1,8 +1,17 @@ package io.f1.backend.global.exception; +import io.f1.backend.global.exception.errorcode.ErrorCode; + public class CustomException extends RuntimeException { - public CustomException(String message) { - super(message); + private final ErrorCode errorCode; + + public CustomException(ErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } + + public ErrorCode getErrorCode() { + return errorCode; } } diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/AuthErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/AuthErrorCode.java new file mode 100644 index 00000000..37ced6c2 --- /dev/null +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/AuthErrorCode.java @@ -0,0 +1,25 @@ +package io.f1.backend.global.exception.errorcode; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum AuthErrorCode implements ErrorCode { + + UNAUTHORIZED("E401001", HttpStatus.UNAUTHORIZED, "로그인이 필요합니다."), + AUTH_SESSION_NOT_FOUND("E401002", HttpStatus.UNAUTHORIZED, "세션이 존재하지 않습니다. 로그인 후 이용해주세요."), + AUTH_SESSION_EXPIRED("E401003", HttpStatus.UNAUTHORIZED, "세션이 만료되었습니다. 다시 로그인해주세요."), + AUTH_SESSION_LOST("E401004", HttpStatus.UNAUTHORIZED, "세션 정보가 유실되었습니다. 다시 로그인해주세요."), + FORBIDDEN("E403001", HttpStatus.FORBIDDEN, "권한이 없습니다."), + + LOGIN_FAILED("E401005", HttpStatus.UNAUTHORIZED, "아이디 또는 비밀번호가 일치하지 않습니다."); + + private final String code; + + private final HttpStatus httpStatus; + + private final String message; + +} diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java new file mode 100644 index 00000000..0a5f0b70 --- /dev/null +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java @@ -0,0 +1,20 @@ +package io.f1.backend.global.exception.errorcode; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum CommonErrorCode implements ErrorCode { + + BAD_REQUEST_DATA("E400001", HttpStatus.BAD_REQUEST, "잘못된 요청 데이터입니다."), + INVALID_PAGINATION("E400006", HttpStatus.BAD_REQUEST, "page와 size는 1 이상의 정수여야 합니다."), + INTERNAL_SERVER_ERROR("E500001", HttpStatus.INTERNAL_SERVER_ERROR, "서버에러가 발생했습니다. 관리자에게 문의해주세요."); + + private final String code; + + private final HttpStatus httpStatus; + + private final String message; +} diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/ErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/ErrorCode.java new file mode 100644 index 00000000..668fe8e7 --- /dev/null +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/ErrorCode.java @@ -0,0 +1,13 @@ +package io.f1.backend.global.exception.errorcode; + +import org.springframework.http.HttpStatus; + +public interface ErrorCode { + + String getCode(); + + HttpStatus getHttpStatus(); + + String getMessage(); + +} diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuestionErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuestionErrorCode.java new file mode 100644 index 00000000..10bdb86e --- /dev/null +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuestionErrorCode.java @@ -0,0 +1,19 @@ +package io.f1.backend.global.exception.errorcode; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum QuestionErrorCode implements ErrorCode { + + QUESTION_NOT_FOUND("E404003", HttpStatus.NOT_FOUND, "존재하지 않는 문제입니다."); + + private final String code; + + private final HttpStatus httpStatus; + + private final String message; + +} diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuizErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuizErrorCode.java new file mode 100644 index 00000000..f7e24383 --- /dev/null +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuizErrorCode.java @@ -0,0 +1,22 @@ +package io.f1.backend.global.exception.errorcode; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum QuizErrorCode implements ErrorCode { + + FILE_SIZE_TOO_LARGE("E400005", HttpStatus.BAD_REQUEST, "파일 크기가 너무 큽니다."), + UNSUPPORTED_MEDIA_TYPE("E415001", HttpStatus.UNSUPPORTED_MEDIA_TYPE, "지원하지 않는 파일 형식입니다."), + INVALID_FILTER("E400007", HttpStatus.BAD_REQUEST, "title 또는 creator 중 하나만 입력 가능합니다."), + QUIZ_NOT_FOUND("E404002", HttpStatus.NOT_FOUND, "존재하지 않는 퀴즈입니다."); + + private final String code; + + private final HttpStatus httpStatus; + + private final String message; + +} diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java new file mode 100644 index 00000000..29f7de6c --- /dev/null +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java @@ -0,0 +1,21 @@ +package io.f1.backend.global.exception.errorcode; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum RoomErrorCode implements ErrorCode { + + ROOM_USER_LIMIT_REACHED("E403002", HttpStatus.FORBIDDEN, "정원이 모두 찼습니다."), + ROOM_GAME_IN_PROGRESS("E403003", HttpStatus.FORBIDDEN, "게임이 진행 중 입니다."), + ROOM_NOT_FOUND("E404005", HttpStatus.NOT_FOUND, "존재하지 않는 방입니다."), + WRONG_PASSWORD("E401006", HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지않습니다."); + + private final String code; + + private final HttpStatus httpStatus; + + private final String message; +} diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/UserErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/UserErrorCode.java new file mode 100644 index 00000000..c8bad37a --- /dev/null +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/UserErrorCode.java @@ -0,0 +1,22 @@ +package io.f1.backend.global.exception.errorcode; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum UserErrorCode implements ErrorCode { + + NICKNAME_EMPTY("E400002", HttpStatus.BAD_REQUEST, "닉네임은 필수 입력입니다."), + NICKNAME_TOO_LONG("E400003", HttpStatus.BAD_REQUEST, "닉네임은 6글자 이하로 입력해야 합니다."), + NICKNAME_NOT_ALLOWED("E400004", HttpStatus.BAD_REQUEST, "한글, 영문, 숫자만 입력해주세요."), + NICKNAME_CONFLICT("E409001", HttpStatus.CONFLICT, "중복된 닉네임입니다."), + USER_NOT_FOUND("E404001", HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다."); + + private final String code; + + private final HttpStatus httpStatus; + + private final String message; +} diff --git a/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java b/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java new file mode 100644 index 00000000..84f78e4d --- /dev/null +++ b/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java @@ -0,0 +1,56 @@ +package io.f1.backend.global.exception.handler; + +import io.f1.backend.global.exception.CustomException; +import io.f1.backend.global.exception.errorcode.CommonErrorCode; +import io.f1.backend.global.exception.errorcode.ErrorCode; +import io.f1.backend.global.exception.response.ErrorResponse; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(CustomException.class) + public ResponseEntity handleCustomException(CustomException e) { + ErrorCode errorCode = e.getErrorCode(); + + ErrorResponse response = new ErrorResponse( + errorCode.getCode(), + errorCode.getMessage() + ); + return new ResponseEntity<>(response, errorCode.getHttpStatus()); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity handleException(Exception e) { + CommonErrorCode errorCode = CommonErrorCode.INTERNAL_SERVER_ERROR; + + ErrorResponse response = new ErrorResponse( + errorCode.getCode(), + errorCode.getMessage() + ); + return new ResponseEntity<>(response, errorCode.getHttpStatus()); + } + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { + + CommonErrorCode code = CommonErrorCode.BAD_REQUEST_DATA; + + String message = e.getBindingResult().getFieldErrors().stream() + .map(FieldError::getDefaultMessage) + .findFirst() + .orElse(code.getMessage()); + + ErrorResponse response = new ErrorResponse( + code.getCode(), + message + ); + + return new ResponseEntity<>(response, code.getHttpStatus()); + + } +} diff --git a/backend/src/main/java/io/f1/backend/global/exception/response/ErrorResponse.java b/backend/src/main/java/io/f1/backend/global/exception/response/ErrorResponse.java new file mode 100644 index 00000000..4f6e5274 --- /dev/null +++ b/backend/src/main/java/io/f1/backend/global/exception/response/ErrorResponse.java @@ -0,0 +1,13 @@ +package io.f1.backend.global.exception.response; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class ErrorResponse { + + private final String code; + private final String message; + +} From f623dda07417c04d851a3576ff1406b588734c98 Mon Sep 17 00:00:00 2001 From: github-actions <> Date: Tue, 15 Jul 2025 02:42:44 +0000 Subject: [PATCH 2/6] =?UTF-8?q?chore:=20Java=20=EC=8A=A4=ED=83=80=EC=9D=BC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/errorcode/AuthErrorCode.java | 3 +- .../exception/errorcode/CommonErrorCode.java | 5 ++-- .../global/exception/errorcode/ErrorCode.java | 1 - .../errorcode/QuestionErrorCode.java | 3 +- .../exception/errorcode/QuizErrorCode.java | 3 +- .../exception/errorcode/RoomErrorCode.java | 2 +- .../exception/errorcode/UserErrorCode.java | 2 +- .../handler/GlobalExceptionHandler.java | 29 +++++++------------ .../exception/response/ErrorResponse.java | 1 - 9 files changed, 19 insertions(+), 30 deletions(-) diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/AuthErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/AuthErrorCode.java index 37ced6c2..54ffb652 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/AuthErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/AuthErrorCode.java @@ -2,12 +2,12 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; + import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor public enum AuthErrorCode implements ErrorCode { - UNAUTHORIZED("E401001", HttpStatus.UNAUTHORIZED, "로그인이 필요합니다."), AUTH_SESSION_NOT_FOUND("E401002", HttpStatus.UNAUTHORIZED, "세션이 존재하지 않습니다. 로그인 후 이용해주세요."), AUTH_SESSION_EXPIRED("E401003", HttpStatus.UNAUTHORIZED, "세션이 만료되었습니다. 다시 로그인해주세요."), @@ -21,5 +21,4 @@ public enum AuthErrorCode implements ErrorCode { private final HttpStatus httpStatus; private final String message; - } diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java index 0a5f0b70..e5fc6986 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java @@ -2,15 +2,16 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; + import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor public enum CommonErrorCode implements ErrorCode { - BAD_REQUEST_DATA("E400001", HttpStatus.BAD_REQUEST, "잘못된 요청 데이터입니다."), INVALID_PAGINATION("E400006", HttpStatus.BAD_REQUEST, "page와 size는 1 이상의 정수여야 합니다."), - INTERNAL_SERVER_ERROR("E500001", HttpStatus.INTERNAL_SERVER_ERROR, "서버에러가 발생했습니다. 관리자에게 문의해주세요."); + INTERNAL_SERVER_ERROR( + "E500001", HttpStatus.INTERNAL_SERVER_ERROR, "서버에러가 발생했습니다. 관리자에게 문의해주세요."); private final String code; diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/ErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/ErrorCode.java index 668fe8e7..a77eaa2d 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/ErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/ErrorCode.java @@ -9,5 +9,4 @@ public interface ErrorCode { HttpStatus getHttpStatus(); String getMessage(); - } diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuestionErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuestionErrorCode.java index 10bdb86e..9b7c0c1e 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuestionErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuestionErrorCode.java @@ -2,12 +2,12 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; + import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor public enum QuestionErrorCode implements ErrorCode { - QUESTION_NOT_FOUND("E404003", HttpStatus.NOT_FOUND, "존재하지 않는 문제입니다."); private final String code; @@ -15,5 +15,4 @@ public enum QuestionErrorCode implements ErrorCode { private final HttpStatus httpStatus; private final String message; - } diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuizErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuizErrorCode.java index f7e24383..e03983b1 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuizErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/QuizErrorCode.java @@ -2,12 +2,12 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; + import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor public enum QuizErrorCode implements ErrorCode { - FILE_SIZE_TOO_LARGE("E400005", HttpStatus.BAD_REQUEST, "파일 크기가 너무 큽니다."), UNSUPPORTED_MEDIA_TYPE("E415001", HttpStatus.UNSUPPORTED_MEDIA_TYPE, "지원하지 않는 파일 형식입니다."), INVALID_FILTER("E400007", HttpStatus.BAD_REQUEST, "title 또는 creator 중 하나만 입력 가능합니다."), @@ -18,5 +18,4 @@ public enum QuizErrorCode implements ErrorCode { private final HttpStatus httpStatus; private final String message; - } diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java index 29f7de6c..191147ac 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java @@ -2,12 +2,12 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; + import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor public enum RoomErrorCode implements ErrorCode { - ROOM_USER_LIMIT_REACHED("E403002", HttpStatus.FORBIDDEN, "정원이 모두 찼습니다."), ROOM_GAME_IN_PROGRESS("E403003", HttpStatus.FORBIDDEN, "게임이 진행 중 입니다."), ROOM_NOT_FOUND("E404005", HttpStatus.NOT_FOUND, "존재하지 않는 방입니다."), diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/UserErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/UserErrorCode.java index c8bad37a..a53f35a4 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/UserErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/UserErrorCode.java @@ -2,12 +2,12 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; + import org.springframework.http.HttpStatus; @Getter @RequiredArgsConstructor public enum UserErrorCode implements ErrorCode { - NICKNAME_EMPTY("E400002", HttpStatus.BAD_REQUEST, "닉네임은 필수 입력입니다."), NICKNAME_TOO_LONG("E400003", HttpStatus.BAD_REQUEST, "닉네임은 6글자 이하로 입력해야 합니다."), NICKNAME_NOT_ALLOWED("E400004", HttpStatus.BAD_REQUEST, "한글, 영문, 숫자만 입력해주세요."), diff --git a/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java b/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java index 84f78e4d..18f86634 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java +++ b/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java @@ -4,6 +4,7 @@ import io.f1.backend.global.exception.errorcode.CommonErrorCode; import io.f1.backend.global.exception.errorcode.ErrorCode; import io.f1.backend.global.exception.response.ErrorResponse; + import org.springframework.http.ResponseEntity; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -17,10 +18,7 @@ public class GlobalExceptionHandler { public ResponseEntity handleCustomException(CustomException e) { ErrorCode errorCode = e.getErrorCode(); - ErrorResponse response = new ErrorResponse( - errorCode.getCode(), - errorCode.getMessage() - ); + ErrorResponse response = new ErrorResponse(errorCode.getCode(), errorCode.getMessage()); return new ResponseEntity<>(response, errorCode.getHttpStatus()); } @@ -28,29 +26,24 @@ public ResponseEntity handleCustomException(CustomException e) { public ResponseEntity handleException(Exception e) { CommonErrorCode errorCode = CommonErrorCode.INTERNAL_SERVER_ERROR; - ErrorResponse response = new ErrorResponse( - errorCode.getCode(), - errorCode.getMessage() - ); + ErrorResponse response = new ErrorResponse(errorCode.getCode(), errorCode.getMessage()); return new ResponseEntity<>(response, errorCode.getHttpStatus()); } @ExceptionHandler(MethodArgumentNotValidException.class) - public ResponseEntity handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { + public ResponseEntity handleMethodArgumentNotValidException( + MethodArgumentNotValidException e) { CommonErrorCode code = CommonErrorCode.BAD_REQUEST_DATA; - String message = e.getBindingResult().getFieldErrors().stream() - .map(FieldError::getDefaultMessage) - .findFirst() - .orElse(code.getMessage()); + String message = + e.getBindingResult().getFieldErrors().stream() + .map(FieldError::getDefaultMessage) + .findFirst() + .orElse(code.getMessage()); - ErrorResponse response = new ErrorResponse( - code.getCode(), - message - ); + ErrorResponse response = new ErrorResponse(code.getCode(), message); return new ResponseEntity<>(response, code.getHttpStatus()); - } } diff --git a/backend/src/main/java/io/f1/backend/global/exception/response/ErrorResponse.java b/backend/src/main/java/io/f1/backend/global/exception/response/ErrorResponse.java index 4f6e5274..42f423c0 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/response/ErrorResponse.java +++ b/backend/src/main/java/io/f1/backend/global/exception/response/ErrorResponse.java @@ -9,5 +9,4 @@ public class ErrorResponse { private final String code; private final String message; - } From b546a5ed62f56b9a29379d16a31b1f06506fecb4 Mon Sep 17 00:00:00 2001 From: limkanghyun Date: Tue, 15 Jul 2025 11:47:44 +0900 Subject: [PATCH 3/6] =?UTF-8?q?:bug:=20fix:=20password=20validation=20@Not?= =?UTF-8?q?Blank=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../f1/backend/domain/game/dto/request/RoomCreateRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/io/f1/backend/domain/game/dto/request/RoomCreateRequest.java b/backend/src/main/java/io/f1/backend/domain/game/dto/request/RoomCreateRequest.java index ec9a347c..3d5ef253 100644 --- a/backend/src/main/java/io/f1/backend/domain/game/dto/request/RoomCreateRequest.java +++ b/backend/src/main/java/io/f1/backend/domain/game/dto/request/RoomCreateRequest.java @@ -11,5 +11,5 @@ public record RoomCreateRequest( @Min(value = 2, message = "방 인원 수는 최소 2명입니다.") @Max(value = 8, message = "방 인원 수는 최대 8명 입니다.") Integer maxUserCount, - @NotNull String password, + @NotBlank String password, @NotNull Boolean locked) {} From 314a58186aab3c2ea211285cbb90f212ffdb1f6e Mon Sep 17 00:00:00 2001 From: limkanghyun Date: Tue, 15 Jul 2025 12:42:05 +0900 Subject: [PATCH 4/6] =?UTF-8?q?:bug:=20fix:=20password=20validation=20@Not?= =?UTF-8?q?Null=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../f1/backend/domain/game/dto/request/RoomCreateRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/io/f1/backend/domain/game/dto/request/RoomCreateRequest.java b/backend/src/main/java/io/f1/backend/domain/game/dto/request/RoomCreateRequest.java index 3d5ef253..ec9a347c 100644 --- a/backend/src/main/java/io/f1/backend/domain/game/dto/request/RoomCreateRequest.java +++ b/backend/src/main/java/io/f1/backend/domain/game/dto/request/RoomCreateRequest.java @@ -11,5 +11,5 @@ public record RoomCreateRequest( @Min(value = 2, message = "방 인원 수는 최소 2명입니다.") @Max(value = 8, message = "방 인원 수는 최대 8명 입니다.") Integer maxUserCount, - @NotBlank String password, + @NotNull String password, @NotNull Boolean locked) {} From 8e7eac50fd0808dbcdca1992e74168b06d55c890 Mon Sep 17 00:00:00 2001 From: limkanghyun Date: Tue, 15 Jul 2025 16:19:59 +0900 Subject: [PATCH 5/6] =?UTF-8?q?:recycle:=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=20=EB=A1=9C=EA=B7=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/errorcode/CommonErrorCode.java | 3 ++- .../handler/GlobalExceptionHandler.java | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java index e5fc6986..a998d9c5 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/CommonErrorCode.java @@ -11,7 +11,8 @@ public enum CommonErrorCode implements ErrorCode { BAD_REQUEST_DATA("E400001", HttpStatus.BAD_REQUEST, "잘못된 요청 데이터입니다."), INVALID_PAGINATION("E400006", HttpStatus.BAD_REQUEST, "page와 size는 1 이상의 정수여야 합니다."), INTERNAL_SERVER_ERROR( - "E500001", HttpStatus.INTERNAL_SERVER_ERROR, "서버에러가 발생했습니다. 관리자에게 문의해주세요."); + "E500001", HttpStatus.INTERNAL_SERVER_ERROR, "서버에러가 발생했습니다. 관리자에게 문의해주세요."), + INVALID_JSON_FORMAT("E400008", HttpStatus.BAD_REQUEST, "요청 형식이 올바르지 않습니다. JSON 문법을 확인해주세요."); private final String code; diff --git a/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java b/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java index 18f86634..fac8ba05 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java +++ b/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java @@ -5,17 +5,21 @@ import io.f1.backend.global.exception.errorcode.ErrorCode; import io.f1.backend.global.exception.response.ErrorResponse; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +@Slf4j @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(CustomException.class) public ResponseEntity handleCustomException(CustomException e) { + log.warn(e.getMessage()); ErrorCode errorCode = e.getErrorCode(); ErrorResponse response = new ErrorResponse(errorCode.getCode(), errorCode.getMessage()); @@ -24,6 +28,7 @@ public ResponseEntity handleCustomException(CustomException e) { @ExceptionHandler(Exception.class) public ResponseEntity handleException(Exception e) { + log.warn("handleException: {}", e.getMessage()); CommonErrorCode errorCode = CommonErrorCode.INTERNAL_SERVER_ERROR; ErrorResponse response = new ErrorResponse(errorCode.getCode(), errorCode.getMessage()); @@ -33,7 +38,7 @@ public ResponseEntity handleException(Exception e) { @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity handleMethodArgumentNotValidException( MethodArgumentNotValidException e) { - + log.warn("MethodArgumentNotValidException: {}", e.getMessage()); CommonErrorCode code = CommonErrorCode.BAD_REQUEST_DATA; String message = @@ -46,4 +51,14 @@ public ResponseEntity handleMethodArgumentNotValidException( return new ResponseEntity<>(response, code.getHttpStatus()); } + + @ExceptionHandler(HttpMessageNotReadableException.class) + public ResponseEntity handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { + log.warn("HttpMessageNotReadableException: {}", e.getMessage()); + CommonErrorCode code = CommonErrorCode.INVALID_JSON_FORMAT; + + ErrorResponse response = new ErrorResponse(code.getCode(), code.getMessage()); + + return new ResponseEntity<>(response, code.getHttpStatus()); + } } From 83ff8d07cdbcb98ee28d5fec50e5b981f4262e3d Mon Sep 17 00:00:00 2001 From: github-actions <> Date: Tue, 15 Jul 2025 07:20:14 +0000 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20Java=20=EC=8A=A4=ED=83=80=EC=9D=BC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/handler/GlobalExceptionHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java b/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java index fac8ba05..c5da75e0 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java +++ b/backend/src/main/java/io/f1/backend/global/exception/handler/GlobalExceptionHandler.java @@ -6,6 +6,7 @@ import io.f1.backend.global.exception.response.ErrorResponse; import lombok.extern.slf4j.Slf4j; + import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.validation.FieldError; @@ -53,7 +54,8 @@ public ResponseEntity handleMethodArgumentNotValidException( } @ExceptionHandler(HttpMessageNotReadableException.class) - public ResponseEntity handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { + public ResponseEntity handleHttpMessageNotReadableException( + HttpMessageNotReadableException e) { log.warn("HttpMessageNotReadableException: {}", e.getMessage()); CommonErrorCode code = CommonErrorCode.INVALID_JSON_FORMAT;