From b1a7f82376d8daca280a883b29ef4ff351084e96 Mon Sep 17 00:00:00 2001 From: Lim Jonguk Date: Tue, 8 Mar 2022 16:08:41 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20validation=20=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EC=A0=95=EB=B3=B4=20[=EC=86=8D=EC=84=B1]=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xit/core/exception/CustomBaseException.java | 12 ++++++------ .../handling/CustomRestExceptionHandler.java | 10 +++++++++- src/main/resources/messages/i18n/error_ko.properties | 1 + .../resources/messages/i18n/error_ko_KR.properties | 1 + 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/messages/i18n/error_ko.properties create mode 100644 src/main/resources/messages/i18n/error_ko_KR.properties diff --git a/src/main/java/com/xit/core/exception/CustomBaseException.java b/src/main/java/com/xit/core/exception/CustomBaseException.java index e07d5b5..2309954 100644 --- a/src/main/java/com/xit/core/exception/CustomBaseException.java +++ b/src/main/java/com/xit/core/exception/CustomBaseException.java @@ -14,7 +14,7 @@ import java.util.ResourceBundle; @Getter @ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Invalid parameter") public class CustomBaseException extends RuntimeException { - ResourceBundle message = ResourceBundle.getBundle("message.error"); +// ResourceBundle message = ResourceBundle.getBundle("error"); private ErrorCode errorCode; private String code; @@ -53,9 +53,9 @@ public class CustomBaseException extends RuntimeException { return super.getMessage(); } - @Override - public String getLocalizedMessage(){ - return message.getString(super.getMessage()); - //return messageSourceAccessor.get - } +// @Override +// public String getLocalizedMessage(){ +// return message.getString(super.getMessage()); +// //return messageSourceAccessor.get +// } } \ No newline at end of file diff --git a/src/main/java/com/xit/core/exception/handling/CustomRestExceptionHandler.java b/src/main/java/com/xit/core/exception/handling/CustomRestExceptionHandler.java index c7499cf..62b99af 100644 --- a/src/main/java/com/xit/core/exception/handling/CustomRestExceptionHandler.java +++ b/src/main/java/com/xit/core/exception/handling/CustomRestExceptionHandler.java @@ -79,16 +79,24 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler { log.error("{}", validErrorMap); log.error("##############################################################################################"); + Optional firstKey = validErrorMap + .keySet() + .stream() + .findFirst(); + + Optional firstMessage = validErrorMap .values() .stream() .findFirst(); + String errMsg = "["+firstKey.orElse("에러 메세지가 정의 되지 않았습니다")+"] "+firstMessage.orElse(""); + RestErrorResponse errorResponse = RestErrorResponse.builder() .status(HttpStatus.BAD_REQUEST.value()) .error(HttpStatus.BAD_REQUEST.name()) .code(HttpStatus.BAD_REQUEST.name()) - .message(firstMessage.orElse("에러 메세지가 정의 되지 않았습니다")) + .message(errMsg) .build(); log.error("##############################################################################################"); diff --git a/src/main/resources/messages/i18n/error_ko.properties b/src/main/resources/messages/i18n/error_ko.properties new file mode 100644 index 0000000..98f115c --- /dev/null +++ b/src/main/resources/messages/i18n/error_ko.properties @@ -0,0 +1 @@ +AAA=\uD55C\uAE00\uC5D0\uB7EC \ No newline at end of file diff --git a/src/main/resources/messages/i18n/error_ko_KR.properties b/src/main/resources/messages/i18n/error_ko_KR.properties new file mode 100644 index 0000000..98f115c --- /dev/null +++ b/src/main/resources/messages/i18n/error_ko_KR.properties @@ -0,0 +1 @@ +AAA=\uD55C\uAE00\uC5D0\uB7EC \ No newline at end of file