diff --git a/src/Action/ContentListAction.php b/src/Action/ContentListAction.php index 04a8aa5..02b1adf 100644 --- a/src/Action/ContentListAction.php +++ b/src/Action/ContentListAction.php @@ -35,8 +35,6 @@ public function handle($contentType, Request $request, ParameterCollection $para $results = $set->get($contentType); - $this->throwErrorOnNoResults($results, 'Bad request: There were no results based upon your criteria!'); - $included = $this->fetchIncludes( $parameters->getParametersByType('includes'), $results, diff --git a/src/Action/FetchAction.php b/src/Action/FetchAction.php index 8951dbe..ee050e8 100644 --- a/src/Action/FetchAction.php +++ b/src/Action/FetchAction.php @@ -4,7 +4,6 @@ use Bolt\Extension\Bolt\JsonApi\Config\Config; use Bolt\Extension\Bolt\JsonApi\Converter\Parameter\Type\Fields; -use Bolt\Extension\Bolt\JsonApi\Exception\ApiInvalidRequestException; use Bolt\Extension\Bolt\JsonApi\Helpers\DataLinks; use Bolt\Extension\Bolt\JsonApi\Parser\Parser; use Bolt\Storage\Entity\Content; @@ -44,19 +43,6 @@ public function __construct( $this->config = $config; } - /** - * @param $results - * @param $message - */ - protected function throwErrorOnNoResults($results, $message) - { - if (! $results || (is_array($results) && count($results) === 0)) { - throw new ApiInvalidRequestException( - $message - ); - } - } - /** * @param $includes * @param $results diff --git a/src/Action/SearchAction.php b/src/Action/SearchAction.php index 56a3330..456baf5 100644 --- a/src/Action/SearchAction.php +++ b/src/Action/SearchAction.php @@ -56,8 +56,6 @@ public function handle($contentType = null, Request $request, ParameterCollectio /** @var Page $page */ $page = $parameters->get('page'); - $this->throwErrorOnNoResults($results, "No search results found for query [$search]"); - foreach ($results as $key => $item) { $contentType = (string) $item->getContenttype(); // optimize this part... diff --git a/src/Action/SingleAction.php b/src/Action/SingleAction.php index b853bd4..e576615 100644 --- a/src/Action/SingleAction.php +++ b/src/Action/SingleAction.php @@ -41,8 +41,10 @@ public function handle($contentType, $slug, $relatedContentType, Request $reques /** @var Content $results */ $results = $this->query->getContent($contentType, $queryParameters); - $this->throwErrorOnNoResults($results, "No [$contentType] found with id/slug: [$slug]."); - + if (! $results) { + throw new ApiNotFoundException("No [$contentType] found with id/slug: [$slug]."); + } + if ($relatedContentType !== null) { $relatedItemsTotal = $results->getRelation($relatedContentType)->count(); if ($relatedItemsTotal <= 0) {