From c5230efad6782c111e51d3c02819a4e5694ca8f3 Mon Sep 17 00:00:00 2001 From: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> Date: Tue, 18 Mar 2025 23:07:40 +0100 Subject: [PATCH] Catch `NodeUpdateService` in `EditNode` & `NodeController` (#1106) --- .../Resources/NodeResource/Pages/EditNode.php | 13 ++++++++++++- .../Api/Application/Nodes/NodeController.php | 15 ++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php b/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php index 5995885d7..98d7099b1 100644 --- a/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php +++ b/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php @@ -555,7 +555,18 @@ class EditNode extends EditRecord ->modalHeading(trans('admin/node.reset_token')) ->modalDescription(trans('admin/node.reset_help')) ->action(function (Node $node) { - $this->nodeUpdateService->handle($node, [], true); + try { + $this->nodeUpdateService->handle($node, [], true); + } catch (Exception) { + Notification::make() + ->title(trans('admin/node.error_connecting', ['node' => $node->name])) + ->body(trans('admin/node.error_connecting_description')) + ->color('warning') + ->icon('tabler-database') + ->warning() + ->send(); + + } Notification::make()->success()->title(trans('admin/node.token_reset'))->send(); $this->fillForm(); }), diff --git a/app/Http/Controllers/Api/Application/Nodes/NodeController.php b/app/Http/Controllers/Api/Application/Nodes/NodeController.php index bd6a3d274..ba2539f7c 100644 --- a/app/Http/Controllers/Api/Application/Nodes/NodeController.php +++ b/app/Http/Controllers/Api/Application/Nodes/NodeController.php @@ -15,6 +15,7 @@ use App\Http\Requests\Api\Application\Nodes\DeleteNodeRequest; use App\Http\Requests\Api\Application\Nodes\UpdateNodeRequest; use App\Http\Controllers\Api\Application\ApplicationApiController; use Dedoc\Scramble\Attributes\Group; +use Exception; #[Group('Node', weight: 0)] class NodeController extends ApplicationApiController @@ -95,11 +96,15 @@ class NodeController extends ApplicationApiController */ public function update(UpdateNodeRequest $request, Node $node): array { - $node = $this->updateService->handle( - $node, - $request->validated(), - $request->input('reset_secret') === true - ); + try { + $node = $this->updateService->handle( + $node, + $request->validated(), + $request->input('reset_secret') === true + ); + } catch (Exception $exception) { + report($exception); + } return $this->fractal->item($node) ->transformWith($this->getTransformer(NodeTransformer::class))