异常类
1. CommonErrors 通用错误枚举
DUPLICATE_KEY("1001", "数据已存在:{}", "exist"),
NO_EXISTS_KEY("1002", "数据不存在:{}", "no_exist"),
DUPLICATE_NAME("1003", "名称已存在:{}", "name_exist"),
RANGE("1004", "{}输入范围限定在{}到{}之间", "range_limit"),
EMPTY("1006", "{}不能为空", "not_empty"),
LENGTH("1007", "{}长度必须是{min}-{max}个字符", "length_limit_param"),
NOT_EXIST_QUARTER("3001", "不存在的季度:{}", "not_exist_quarter"),
NOT_EXIST_MONTH("3002", "不存在的月份:{}", "not_exist_month"),
NOT_EXIST_DATE_RANGE("3003", "不存在的时间区间:{}", "not_exist_date_range"),
FEIGN_INVOKE("4001", "服务器繁忙,请稍候再试!{}", "feign_invoke"),
SYS_BUSY("4002", "系统繁忙,请稍候再试", "sys_busy")
2. CommonException 通用exception类
public CommonException(CommonErrors commonErrors, Object... params) {
super(commonErrors.getCode(), commonErrors.format(params));
}
public CommonException(String code, String msg) {
super(code, msg);
}
3. DuplicateException 数据重复异常类
public DuplicateException(Object... params) {
super(DUPLICATE_KEY.getCode(), DUPLICATE_KEY.format(params));
}
4. DuplicateNameException 名称重复异常类
public DuplicateNameException(Object... params) {
super(DUPLICATE_NAME.getCode(), DUPLICATE_NAME.format(params));
}
5. FeignInvokeException feign内部调用异常类
public FeignInvokeException(Object... params) {
super(FEIGN_INVOKE.getCode(), FEIGN_INVOKE.format(params));
}
6.NotExistException 数据不存在异常类
public NotExistException(Object... params) {
super(NO_EXISTS_KEY.getCode(), NO_EXISTS_KEY.format(params));
}
7. OutOfLengthException 超出长度异常类
public OutOfLengthException(Object... params) {
super(LENGTH.getCode(), LENGTH.format(params));
}
8. OutOfRangeException 超出范围异常类
public OutOfRangeException(Object... params) {
super(RANGE.getCode(), RANGE.format(params));
}
9. RequiredException 必填属性异常类
public RequiredException(Object... params) {
super(EMPTY.getCode(), EMPTY.format(params));
}
使用示例
if (CharSequenceUtil.isBlank(id)) {
throw new RequiredException(ID);
}
文档更新时间: 2022-02-21 17:23 作者:陆鸿睿