From 0fdba8c054c7d14f1505e362133821924c9abf61 Mon Sep 17 00:00:00 2001 From: Rev Date: Sun, 10 Oct 2021 13:09:11 +0900 Subject: [PATCH] use custom exception instead of the generic one --- app/Data/ItemsCollection.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Data/ItemsCollection.php b/app/Data/ItemsCollection.php index f7a5894..03f962d 100644 --- a/app/Data/ItemsCollection.php +++ b/app/Data/ItemsCollection.php @@ -2,6 +2,7 @@ namespace App\Data; +use App\Exceptions\ItemNotFoundException; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; @@ -43,9 +44,10 @@ class ItemsCollection /** * @param string $id * @return array + * @throws ItemNotFoundException */ - public function getItemById(string $id) + public function getItemById(string $id): array { - return $this->data[$id]; + return $this->data[$id] ?? throw new ItemNotFoundException('Item not found'); } }