🎨 修改BallCatException => BusinessException, 增加通用性

This commit is contained in:
b2baccline
2020-03-27 22:08:15 +08:00
parent f4ace29984
commit 3883e9e7fc
6 changed files with 19 additions and 19 deletions

View File

@@ -9,7 +9,7 @@ import com.hccake.ballcat.admin.modules.sys.model.entity.SysDictItem;
import com.hccake.ballcat.admin.modules.sys.model.qo.SysDictQO;
import com.hccake.ballcat.admin.modules.sys.service.SysDictItemService;
import com.hccake.ballcat.admin.modules.sys.service.SysDictService;
import com.hccake.ballcat.common.core.exception.BallCatException;
import com.hccake.ballcat.common.core.exception.BusinessException;
import com.hccake.ballcat.common.core.result.BaseResultCode;
import com.hccake.ballcat.common.core.vo.SelectData;
import lombok.RequiredArgsConstructor;
@@ -66,7 +66,7 @@ public class SysDictManager {
// 查询现有数据
SysDict oldData = sysDictService.getById(sysDict.getId());
if (DictTypeEnum.SYSTEM.getType().equals(oldData.getType())) {
throw new BallCatException(
throw new BusinessException(
BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "系统内置字典项目不能修改"
);
}
@@ -83,7 +83,7 @@ public class SysDictManager {
// 查询现有数据
SysDict dict = sysDictService.getById(id);
if (DictTypeEnum.SYSTEM.getType().equals(dict.getType())) {
throw new BallCatException(
throw new BusinessException(
BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "系统内置字典项目不能删除"
);
}
@@ -127,7 +127,7 @@ public class SysDictManager {
SysDict dict = sysDictService.getByCode(sysDictItem.getDictCode());
// 校验是否系统内置
if (DictTypeEnum.SYSTEM.getType().equals(dict.getType())) {
throw new BallCatException(
throw new BusinessException(
BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "系统内置字典项目不能修改"
);
}
@@ -146,7 +146,7 @@ public class SysDictManager {
SysDict dict = sysDictService.getByCode(dictItem.getDictCode());
// 校验是否系统内置
if (DictTypeEnum.SYSTEM.getType().equals(dict.getType())) {
throw new BallCatException(
throw new BusinessException(
BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "系统内置字典项目不能删除"
);
}

View File

@@ -9,7 +9,7 @@ import com.hccake.ballcat.admin.modules.sys.model.entity.SysPermission;
import com.hccake.ballcat.admin.modules.sys.model.entity.SysRolePermission;
import com.hccake.ballcat.admin.modules.sys.model.vo.PermissionVO;
import com.hccake.ballcat.admin.modules.sys.service.SysPermissionService;
import com.hccake.ballcat.common.core.exception.BallCatException;
import com.hccake.ballcat.common.core.exception.BusinessException;
import com.hccake.ballcat.common.core.result.BaseResultCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -42,7 +42,7 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
List<SysPermission> permissionList = this.list(Wrappers.<SysPermission>query()
.lambda().eq(SysPermission::getParentId, id));
if (CollUtil.isNotEmpty(permissionList)) {
throw new BallCatException(BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "菜单含有下级不能删除");
throw new BusinessException(BaseResultCode.LOGIC_CHECK_ERROR.getCode(), "菜单含有下级不能删除");
}
sysRolePermissionMapper

View File

@@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hccake.ballcat.api.modules.api.model.entity.ApiAccessLog;
import com.hccake.ballcat.api.modules.log.service.ApiAccessLogService;
import com.hccake.ballcat.common.core.exception.BallCatException;
import com.hccake.ballcat.common.core.exception.BusinessException;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@@ -76,7 +76,7 @@ public class TestController {
@PostMapping("/errortest")
public String error(){
throw new BallCatException(9999, "Error Test");
throw new BusinessException(9999, "Error Test");
}

View File

@@ -1,7 +1,7 @@
package com.hccake.ballcat.common.conf.web;
import com.hccake.ballcat.commom.log.error.service.ErrorLogHandlerService;
import com.hccake.ballcat.common.core.exception.BallCatException;
import com.hccake.ballcat.common.core.exception.BusinessException;
import com.hccake.ballcat.common.core.result.R;
import com.hccake.ballcat.common.core.result.SystemResultCode;
import lombok.RequiredArgsConstructor;
@@ -50,9 +50,9 @@ public class GlobalExceptionHandlerResolver {
* @param e the e
* @return R
*/
@ExceptionHandler(BallCatException.class)
@ExceptionHandler(BusinessException.class)
@ResponseStatus(HttpStatus.OK)
public R handleBallCatException(BallCatException e) {
public R handleBallCatException(BusinessException e) {
log.error("自定义异常信息 ex={}", e.getMessage(), e);
errorLogHandlerService.handle(e);
return R.failed(SystemResultCode.SERVER_ERROR, e.getLocalizedMessage());

View File

@@ -1,6 +1,6 @@
package com.hccake.ballcat.common.conf.web;
import com.hccake.ballcat.common.core.exception.BallCatException;
import com.hccake.ballcat.common.core.exception.BusinessException;
import com.hccake.ballcat.common.core.result.SystemResultCode;
/**
@@ -9,7 +9,7 @@ import com.hccake.ballcat.common.core.result.SystemResultCode;
* @date 2019/10/19 16:52
* sql防注入校验异常
*/
public class SqlCheckedException extends BallCatException {
public class SqlCheckedException extends BusinessException {
public SqlCheckedException(SystemResultCode systemResultMsg) {
super(systemResultMsg);
}

View File

@@ -8,30 +8,30 @@ import lombok.Getter;
* @author Hccake
*/
@Getter
public class BallCatException extends RuntimeException {
public class BusinessException extends RuntimeException {
private String msg;
private int code;
public BallCatException(ResultCode resultCode) {
public BusinessException(ResultCode resultCode) {
super(resultCode.getMessage());
this.code = resultCode.getCode();
this.msg = resultCode.getMessage();
}
public BallCatException(ResultCode resultCode, Throwable e) {
public BusinessException(ResultCode resultCode, Throwable e) {
super(resultCode.getMessage(), e);
this.code = resultCode.getCode();
this.msg = resultCode.getMessage();
}
public BallCatException(int code, String msg) {
public BusinessException(int code, String msg) {
super(msg);
this.msg = msg;
this.code = code;
}
public BallCatException( int code, String msg, Throwable e) {
public BusinessException(int code, String msg, Throwable e) {
super(msg, e);
this.msg = msg;
this.code = code;