Skip to content

Commit

Permalink
Merge pull request #80 from d-m-/fix-issue-70
Browse files Browse the repository at this point in the history
Return empty lists with status 200 instead of 400 - Fix for issue #70
  • Loading branch information
xiaohutai authored Apr 23, 2018
2 parents d99e355 + 052b2c9 commit d5e6142
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/Action/ContentListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 0 additions & 14 deletions src/Action/FetchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/Action/SearchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
6 changes: 4 additions & 2 deletions src/Action/SingleAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d5e6142

Please sign in to comment.