refactor: 规范状态码、抛出异常的使用

This commit is contained in:
xboard
2023-12-07 04:01:32 +08:00
parent c25803aa74
commit 189b247ad8
71 changed files with 663 additions and 910 deletions
@@ -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
];