fix : validation 메세지 정보 [속성] 추가

dev
Lim Jonguk 3 years ago
parent a4e78c5504
commit b1a7f82376

@ -14,7 +14,7 @@ import java.util.ResourceBundle;
@Getter @Getter
@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Invalid parameter") @ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Invalid parameter")
public class CustomBaseException extends RuntimeException { public class CustomBaseException extends RuntimeException {
ResourceBundle message = ResourceBundle.getBundle("message.error"); // ResourceBundle message = ResourceBundle.getBundle("error");
private ErrorCode errorCode; private ErrorCode errorCode;
private String code; private String code;
@ -53,9 +53,9 @@ public class CustomBaseException extends RuntimeException {
return super.getMessage(); return super.getMessage();
} }
@Override // @Override
public String getLocalizedMessage(){ // public String getLocalizedMessage(){
return message.getString(super.getMessage()); // return message.getString(super.getMessage());
//return messageSourceAccessor.get // //return messageSourceAccessor.get
} // }
} }

@ -79,16 +79,24 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
log.error("{}", validErrorMap); log.error("{}", validErrorMap);
log.error("##############################################################################################"); log.error("##############################################################################################");
Optional<String> firstKey = validErrorMap
.keySet()
.stream()
.findFirst();
Optional<String> firstMessage = validErrorMap Optional<String> firstMessage = validErrorMap
.values() .values()
.stream() .stream()
.findFirst(); .findFirst();
String errMsg = "["+firstKey.orElse("에러 메세지가 정의 되지 않았습니다")+"] "+firstMessage.orElse("");
RestErrorResponse errorResponse = RestErrorResponse.builder() RestErrorResponse errorResponse = RestErrorResponse.builder()
.status(HttpStatus.BAD_REQUEST.value()) .status(HttpStatus.BAD_REQUEST.value())
.error(HttpStatus.BAD_REQUEST.name()) .error(HttpStatus.BAD_REQUEST.name())
.code(HttpStatus.BAD_REQUEST.name()) .code(HttpStatus.BAD_REQUEST.name())
.message(firstMessage.orElse("에러 메세지가 정의 되지 않았습니다")) .message(errMsg)
.build(); .build();
log.error("##############################################################################################"); log.error("##############################################################################################");

Loading…
Cancel
Save