refactor: 规范Expection处理

This commit is contained in:
xboard
2023-12-04 20:40:49 +08:00
parent aa0fe64afe
commit 0ab7dee52d
65 changed files with 625 additions and 362 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\V1\Admin\Server;
use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;
use App\Models\Plan;
use App\Models\ServerGroup;
@@ -39,7 +40,7 @@ class GroupController extends Controller
public function save(Request $request)
{
if (empty($request->input('name'))) {
abort(500, '组名不能为空');
throw new ApiException(500, '组名不能为空');
}
if ($request->input('id')) {
@@ -59,22 +60,22 @@ class GroupController extends Controller
if ($request->input('id')) {
$serverGroup = ServerGroup::find($request->input('id'));
if (!$serverGroup) {
abort(500, '组不存在');
throw new ApiException(500, '组不存在');
}
}
$servers = ServerVmess::all();
foreach ($servers as $server) {
if (in_array($request->input('id'), $server->group_id)) {
abort(500, '该组已被节点所使用,无法删除');
throw new ApiException(500, '该组已被节点所使用,无法删除');
}
}
if (Plan::where('group_id', $request->input('id'))->first()) {
abort(500, '该组已被订阅所使用,无法删除');
throw new ApiException(500, '该组已被订阅所使用,无法删除');
}
if (User::where('group_id', $request->input('id'))->first()) {
abort(500, '该组已被用户所使用,无法删除');
throw new ApiException(500, '该组已被用户所使用,无法删除');
}
return response([
'data' => $serverGroup->delete()