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\Http\Requests\Admin\ServerTrojanSave;
use App\Http\Requests\Admin\ServerTrojanUpdate;
@@ -17,12 +18,12 @@ class TrojanController extends Controller
if ($request->input('id')) {
$server = ServerTrojan::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
@@ -30,7 +31,7 @@ class TrojanController extends Controller
}
if (!ServerTrojan::create($params)) {
abort(500, '创建失败');
throw new ApiException(500, '创建失败');
}
return response([
@@ -43,7 +44,7 @@ class TrojanController extends Controller
if ($request->input('id')) {
$server = ServerTrojan::find($request->input('id'));
if (!$server) {
abort(500, '节点ID不存在');
throw new ApiException(500, '节点ID不存在');
}
}
return response([
@@ -60,12 +61,12 @@ class TrojanController extends Controller
$server = ServerTrojan::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([
@@ -78,10 +79,10 @@ class TrojanController extends Controller
$server = ServerTrojan::find($request->input('id'));
$server->show = 0;
if (!$server) {
abort(500, '服务器不存在');
throw new ApiException(500, '服务器不存在');
}
if (!ServerTrojan::create($server->toArray())) {
abort(500, '复制失败');
throw new ApiException(500, '复制失败');
}
return response([