com.nxyfan.framework.common.exception.CommonException Maven / Gradle / Ivy
package com.nxyfan.framework.common.exception;
import com.nxyfan.framework.common.enums.CommonExceptionEnum;
import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;
/**
* 通用异常
*
* @author amour
* @date 2020/4/8 15:54
*/
@SuppressWarnings("serial")
@Getter
@Setter
public class CommonException extends RuntimeException {
private Integer code;
private String msg;
public CommonException() {
super("出错了,请联系工程师");
this.code = 500;
this.msg = "出错了,请联系工程师";
}
/**
*
* Describe: 业务异常
* Author: amour
* Create Time: 2022年10月30日 下午6:03:42
* @param msg
* @param arguments
* @return 业务异常
*/
public static CommonException bizException(String msg, Object... arguments) {
return new CommonException(CommonExceptionEnum.ERROR400.getCode(), msg, arguments);
}
public CommonException(String msg, Object... arguments) {
super(StrUtil.format(msg, arguments));
this.code = CommonExceptionEnum.ERROR500.getCode();
this.msg = StrUtil.format(msg, arguments);
}
public CommonException(Integer code, String msg, Object... arguments) {
super(StrUtil.format(msg, arguments));
this.code = code;
this.msg = StrUtil.format(msg, arguments);
}
}