mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-15 12:30:51 +08:00
refactor: 规范Expection处理
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user