From c3750af9dfdb6ae069b1974cdcab1d8cfaa5d5be Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Wed, 9 Oct 2024 22:56:11 +0200 Subject: [PATCH] improve TagNotFound error --- lib/Errors/TagNotFound.php | 3 +++ lib/Service/TagService.php | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Errors/TagNotFound.php b/lib/Errors/TagNotFound.php index 210c065..b9e5633 100644 --- a/lib/Errors/TagNotFound.php +++ b/lib/Errors/TagNotFound.php @@ -3,4 +3,7 @@ namespace OCA\GroupfolderTags\Errors; class TagNotFound extends NotFoundException { + public function __construct($groupFolderId, $tagKey) { + parent::__construct(OCA\GroupfolderTags\Db\Tag::class, ["groupFolderId" => $groupFolderId, "tagKey" => $tagKey]); + } } \ No newline at end of file diff --git a/lib/Service/TagService.php b/lib/Service/TagService.php index 298ac5e..0cbbb25 100644 --- a/lib/Service/TagService.php +++ b/lib/Service/TagService.php @@ -22,10 +22,10 @@ class TagService { return $this->mapper->findAll($tagKey, $tagValue); } - private function handleException(Exception $e): void { + private function handleException(Exception $e, int $groupFolderId, string $tagKey): void { if ($e instanceof DoesNotExistException || $e instanceof MultipleObjectsReturnedException) { - throw new TagNotFound($e->getMessage()); + throw new TagNotFound($groupFolderId, $tagKey); } else { throw $e; } @@ -35,11 +35,11 @@ class TagService { try { return $this->mapper->find($groupFolderId, $tagKey); } catch (Exception $e) { - $this->handleException($e); + $this->handleException($e, $groupFolderId, $tagKey); } } - public function update(int $groupFolderId, string $key, ?string $value): Tag { + public function update(int $groupFolderId, string $key, ?string $value = null): Tag { try { $tag = $this->find($groupFolderId, $key); $tagExists = True; @@ -61,13 +61,13 @@ class TagService { } } - public function delete(int $groupFolderId, string $key): Tag { + public function delete(int $groupFolderId, string $tagKey): Tag { try { - $tag = $this->mapper->find($groupFolderId, $key); + $tag = $this->mapper->find($groupFolderId, $tagKey); $this->mapper->delete($tag); return $tag; } catch (Exception $e) { - $this->handleException($e); + $this->handleException($e, $groupFolderId, $tagKey); } }