feat: 优化异常处理,使用BusinessException替代setError和rollback

This commit is contained in:
mkm 2024-08-27 20:50:53 +08:00
parent 94df5f79de
commit 79edaa03f1
3 changed files with 13 additions and 20 deletions

View File

@ -20,6 +20,7 @@ use app\common\{
logic\BaseLogic,
model\auth\SystemRoleMenu
};
use support\exception\BusinessException;
use think\facade\Db;
@ -66,8 +67,7 @@ class RoleLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}
@ -110,8 +110,7 @@ class RoleLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}

View File

@ -21,6 +21,7 @@ use app\common\model\tools\GenerateTable;
use app\common\service\generator\GenerateService;
use support\Cache;
use support\Container;
use support\exception\BusinessException;
use think\facade\Db;
@ -78,8 +79,7 @@ class GeneratorLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}
@ -134,8 +134,7 @@ class GeneratorLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}
@ -157,8 +156,7 @@ class GeneratorLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}
@ -187,8 +185,7 @@ class GeneratorLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}
@ -228,8 +225,7 @@ class GeneratorLogic extends BaseLogic
return ['file' => $zipFile];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}
@ -252,8 +248,7 @@ class GeneratorLogic extends BaseLogic
return Container::get(GenerateService::class)->preview($table);
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}

View File

@ -20,6 +20,7 @@ use app\common\{
logic\BaseLogic,
model\auth\SystemRoleMenu
};
use support\exception\BusinessException;
use think\facade\Db;
@ -66,8 +67,7 @@ class RoleLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}
@ -110,8 +110,7 @@ class RoleLogic extends BaseLogic
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
throw new BusinessException($e->getMessage());
}
}