mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 19:40:53 +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\ServerHysteria;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -44,12 +45,12 @@ class HysteriaController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -57,7 +58,7 @@ class HysteriaController extends Controller
|
||||
}
|
||||
|
||||
if (!ServerHysteria::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
throw new ApiException(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -70,7 +71,7 @@ class HysteriaController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
throw new ApiException(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
@@ -92,12 +93,12 @@ class HysteriaController extends Controller
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
throw new ApiException(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -110,10 +111,10 @@ class HysteriaController extends Controller
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerHysteria::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
throw new ApiException(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
Reference in New Issue
Block a user