mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-23 11:27:30 +08:00
refactor: 规范状态码、抛出异常的使用
This commit is contained in:
@@ -44,24 +44,26 @@ class RouteController extends Controller
|
||||
try {
|
||||
$route = ServerRoute::find($request->input('id'));
|
||||
$route->update($params);
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
return $this->success(true);
|
||||
} catch (\Exception $e) {
|
||||
throw new ApiException(500, '保存失败');
|
||||
\Log::error($e);
|
||||
return $this->fail([500,'保存失败']);
|
||||
}
|
||||
}
|
||||
if (!ServerRoute::create($params)) throw new ApiException(500, '创建失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
try{
|
||||
ServerRoute::create($params);
|
||||
return $this->success(true);
|
||||
}catch(\Exception $e){
|
||||
\Log::error($e);
|
||||
return $this->fail([500,'创建失败']);
|
||||
}
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
$route = ServerRoute::find($request->input('id'));
|
||||
if (!$route) throw new ApiException(500, '路由不存在');
|
||||
if (!$route->delete()) throw new ApiException(500, '删除失败');
|
||||
if (!$route) throw new ApiException('路由不存在');
|
||||
if (!$route->delete()) throw new ApiException('删除失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user