feat: Exception 메세지 파라메터 처리 추가

- 에러메세지{0}{1}... 바인딩 처리
dev
gitea-관리자 1 year ago
parent 4a9a48e904
commit 0c65d908ad

@ -52,4 +52,7 @@ public class EgovMessageSource extends ReloadableResourceBundleMessageSource imp
return getReloadableResourceBundleMessageSource().getMessage(code, null, Locale.getDefault()); return getReloadableResourceBundleMessageSource().getMessage(code, null, Locale.getDefault());
} }
public String getMessage(String code, Object[] messageParam) {
return getReloadableResourceBundleMessageSource().getMessage(code, messageParam, Locale.getDefault());
}
} }

@ -1,17 +1,16 @@
package kr.xit.core.exception; package kr.xit.core.exception;
import egovframework.com.cmm.EgovMessageSource;
import java.util.Locale; import java.util.Locale;
import org.egovframe.rte.fdl.cmmn.exception.BaseRuntimeException;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import kr.xit.core.consts.ErrorCode; import kr.xit.core.consts.ErrorCode;
import kr.xit.core.spring.annotation.SecurityPolicy; import kr.xit.core.spring.util.CoreSpringUtils;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.egovframe.rte.fdl.cmmn.exception.BaseRuntimeException;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/** /**
* <pre> * <pre>
@ -36,6 +35,8 @@ public class BizRuntimeException extends BaseRuntimeException {
private String code; private String code;
private ErrorCode errorCode; private ErrorCode errorCode;
private static final EgovMessageSource messageSource = CoreSpringUtils.getMessageSource();
/** /**
* BizRuntimeException . * BizRuntimeException .
* @param errorCode ErrorCode * @param errorCode ErrorCode
@ -74,6 +75,13 @@ public class BizRuntimeException extends BaseRuntimeException {
return e; return e;
} }
public static BizRuntimeException create(String code, Object[] messageParameters) {
BizRuntimeException e = new BizRuntimeException();
e.setCode(code);
e.setMessage(messageSource.getMessage(code, messageParameters));
return e;
}
/** /**
* BizRuntimeException . * BizRuntimeException .
* @param wrappedException Exception * @param wrappedException Exception
@ -189,4 +197,8 @@ public class BizRuntimeException extends BaseRuntimeException {
public HttpStatus getHttpStatus(){ public HttpStatus getHttpStatus(){
return HttpStatus.BAD_REQUEST; return HttpStatus.BAD_REQUEST;
} }
public static void main(String[] args) {
}
} }

Loading…
Cancel
Save