mirror of
https://github.com/verdigado/groupfolder_tags.git
synced 2024-12-06 11:42:42 +01:00
improve TagNotFound error
This commit is contained in:
parent
b59dad378b
commit
c3750af9df
2 changed files with 10 additions and 7 deletions
|
@ -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]);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue