feat: 优化异常处理,使用BusinessException替代setError和rollback
This commit is contained in:
parent
94df5f79de
commit
79edaa03f1
@ -20,6 +20,7 @@ use app\common\{
|
|||||||
logic\BaseLogic,
|
logic\BaseLogic,
|
||||||
model\auth\SystemRoleMenu
|
model\auth\SystemRoleMenu
|
||||||
};
|
};
|
||||||
|
use support\exception\BusinessException;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
@ -66,8 +67,7 @@ class RoleLogic extends BaseLogic
|
|||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,8 +110,7 @@ class RoleLogic extends BaseLogic
|
|||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ use app\common\model\tools\GenerateTable;
|
|||||||
use app\common\service\generator\GenerateService;
|
use app\common\service\generator\GenerateService;
|
||||||
use support\Cache;
|
use support\Cache;
|
||||||
use support\Container;
|
use support\Container;
|
||||||
|
use support\exception\BusinessException;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
@ -78,8 +79,7 @@ class GeneratorLogic extends BaseLogic
|
|||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,8 +134,7 @@ class GeneratorLogic extends BaseLogic
|
|||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,8 +156,7 @@ class GeneratorLogic extends BaseLogic
|
|||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,8 +185,7 @@ class GeneratorLogic extends BaseLogic
|
|||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,8 +225,7 @@ class GeneratorLogic extends BaseLogic
|
|||||||
return ['file' => $zipFile];
|
return ['file' => $zipFile];
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,8 +248,7 @@ class GeneratorLogic extends BaseLogic
|
|||||||
return Container::get(GenerateService::class)->preview($table);
|
return Container::get(GenerateService::class)->preview($table);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ use app\common\{
|
|||||||
logic\BaseLogic,
|
logic\BaseLogic,
|
||||||
model\auth\SystemRoleMenu
|
model\auth\SystemRoleMenu
|
||||||
};
|
};
|
||||||
|
use support\exception\BusinessException;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
@ -66,8 +67,7 @@ class RoleLogic extends BaseLogic
|
|||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,8 +110,7 @@ class RoleLogic extends BaseLogic
|
|||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::$error = $e->getMessage();
|
throw new BusinessException($e->getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user