diff --git a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php index f8c77aa274..b749d6da7a 100644 --- a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php @@ -792,7 +792,11 @@ public function form(Form $form): Form ->color('warning') ->hidden(fn (Server $server) => $server->isSuspended()) ->action(function (SuspensionService $suspensionService, Server $server) { - $suspensionService->handle($server, SuspensionService::ACTION_SUSPEND); + try { + $suspensionService->handle($server, SuspensionService::ACTION_SUSPEND); + } catch (\Exception $exception) { + Notification::make()->warning()->title('Server Suspension')->body($exception->getMessage())->send(); + } Notification::make()->success()->title('Server Suspended!')->send(); $this->refreshFormData(['status', 'docker']); @@ -802,7 +806,11 @@ public function form(Form $form): Form ->color('success') ->hidden(fn (Server $server) => !$server->isSuspended()) ->action(function (SuspensionService $suspensionService, Server $server) { - $suspensionService->handle($server, SuspensionService::ACTION_UNSUSPEND); + try { + $suspensionService->handle($server, SuspensionService::ACTION_UNSUSPEND); + } catch (\Exception $exception) { + Notification::make()->warning()->title('Server Suspension')->body($exception->getMessage())->send(); + } Notification::make()->success()->title('Server Unsuspended!')->send(); $this->refreshFormData(['status', 'docker']); diff --git a/app/Services/Servers/SuspensionService.php b/app/Services/Servers/SuspensionService.php index 0f78460b81..eb961501be 100644 --- a/app/Services/Servers/SuspensionService.php +++ b/app/Services/Servers/SuspensionService.php @@ -7,6 +7,7 @@ use Webmozart\Assert\Assert; use App\Models\Server; use App\Repositories\Daemon\DaemonServerRepository; +use Doctrine\DBAL\Exception\ConnectionException; use Symfony\Component\HttpKernel\Exception\ConflictHttpException; class SuspensionService @@ -55,11 +56,7 @@ public function handle(Server $server, string $action = self::ACTION_SUSPEND): v try { // Tell daemon to re-sync the server state. $this->daemonServerRepository->setServer($server)->sync(); - } catch (\Exception $exception) { - // Rollback the server's suspension status if daemon fails to sync the server. - $server->update([ - 'status' => $isSuspending ? null : ServerState::Suspended, - ]); + } catch (ConnectionException $exception) { throw $exception; } }