5 changed files with 108 additions and 5 deletions
@ -0,0 +1,87 @@ |
|||
package com.epmet.commons.tools.exception; |
|||
|
|||
import com.epmet.commons.tools.utils.MessageUtils; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
/** |
|||
* @author zhaoqifeng |
|||
* @dscription |
|||
* @date 2020/4/29 18:13 |
|||
*/ |
|||
public class ValidateException extends RuntimeException { |
|||
private static final long serialVersionUID = 1L; |
|||
private int code; |
|||
private String msg; |
|||
|
|||
public ValidateException(int code) { |
|||
this.code = code; |
|||
this.msg = EpmetErrorCode.getMsg(code); |
|||
if (StringUtils.isBlank(this.msg)) { |
|||
this.msg = MessageUtils.getMessage(code); |
|||
} |
|||
} |
|||
|
|||
public ValidateException(int code, String... params) { |
|||
this.code = code; |
|||
this.msg = EpmetErrorCode.getMsg(code); |
|||
if (StringUtils.isBlank(this.msg)) { |
|||
this.msg = MessageUtils.getMessage(code, params); |
|||
} |
|||
} |
|||
|
|||
public ValidateException(int code, Throwable e) { |
|||
super(e); |
|||
this.code = code; |
|||
this.msg = EpmetErrorCode.getMsg(code); |
|||
if (StringUtils.isBlank(this.msg)) { |
|||
this.msg = MessageUtils.getMessage(code); |
|||
} |
|||
} |
|||
|
|||
public ValidateException(int code, Throwable e, String... params) { |
|||
super(e); |
|||
this.code = code; |
|||
|
|||
} |
|||
|
|||
public ValidateException(int code, String msg) { |
|||
this.code = code; |
|||
if (StringUtils.isBlank(msg)) { |
|||
this.msg = EpmetErrorCode.getMsg(code); |
|||
if (StringUtils.isBlank(this.msg)) { |
|||
this.msg = MessageUtils.getMessage(code, msg); |
|||
} |
|||
} else { |
|||
this.msg = msg; |
|||
} |
|||
} |
|||
|
|||
|
|||
public ValidateException(String msg) { |
|||
super(msg); |
|||
this.code = EpmetErrorCode.VALIDATE_ERROR.getCode(); |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public ValidateException(String msg, Throwable e) { |
|||
super(msg, e); |
|||
this.code = EpmetErrorCode.VALIDATE_ERROR.getCode(); |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public String getMsg() { |
|||
return msg; |
|||
} |
|||
|
|||
public void setMsg(String msg) { |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public int getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public void setCode(int code) { |
|||
this.code = code; |
|||
} |
|||
} |
Loading…
Reference in new issue