From b3453a4604158e51ef52a7a3b7a8263ccab43e31 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sat, 21 Feb 2026 21:08:42 +0200 Subject: [PATCH] throw exception if text doesnt exist --- app/Node/UseCases/CreateNode.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Node/UseCases/CreateNode.php b/app/Node/UseCases/CreateNode.php index 736ad26..f67b2de 100644 --- a/app/Node/UseCases/CreateNode.php +++ b/app/Node/UseCases/CreateNode.php @@ -6,6 +6,7 @@ use App\Node\Node; use App\Node\CreateNodeDto; use App\Node\NodeRepository; use App\Text\TextRepository; +use DomainException; class CreateNode { @@ -16,7 +17,12 @@ class CreateNode public function execute(CreateNodeRequest $request): Node { - $text = $this->textRepo->find($request->textId); + $id = $request->textId; + $text = $this->textRepo->find($id); + if ($text === null) { + throw new DomainException("Text with id: $id doesnt exist"); + } + return $this->nodeRepo->create(new CreateNodeDto( text: $text, title: $request->title,