Skip to content

Commit

Permalink
EZP-23465: fixed: throw InvalidArgumentException on invalid target
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed Jan 30, 2015
1 parent 2c016f2 commit a352e62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use eZ\Publish\Core\Persistence\Elasticsearch\Content\Search\SortClauseVisitor\FieldBase;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use RuntimeException;
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;

/**
* Visits the Field sort clause
Expand All @@ -33,6 +33,8 @@ public function canVisit( SortClause $sortClause )
/**
* Map field value to a proper Elasticsearch representation
*
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no sortable fields are found for the given sort clause target.
*
* @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause
*
* @return mixed
Expand All @@ -49,7 +51,11 @@ public function visit( SortClause $sortClause )

if ( $fieldName === null )
{
throw new RuntimeException( "No sortable fields found for '{$target->fieldIdentifier}' on '{$target->typeIdentifier}'" );
throw new InvalidArgumentException(
"\$sortClause->target",
"No searchable fields found for the given sort clause target ".
"'{$target->fieldIdentifier}' on '{$target->typeIdentifier}'."
);
}

/** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\FieldTarget $target */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use eZ\Publish\Core\Persistence\Elasticsearch\Content\Search\SortClauseVisitor\FieldBase;
use eZ\Publish\Core\Persistence\Elasticsearch\Content\Search\SortClauseVisitor;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use RuntimeException;
use eZ\Publish\API\Repository\Values\Content\Query\CustomFieldInterface;
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;

/**
* Visits the MapLocationDistance sort clause
Expand Down Expand Up @@ -61,7 +61,11 @@ public function visit( SortClause $sortClause )

if ( $fieldName === null )
{
throw new RuntimeException( "No sortable fields found" );
throw new InvalidArgumentException(
"\$sortClause->target",
"No searchable fields found for the given sort clause target ".
"'{$target->fieldIdentifier}' on '{$target->typeIdentifier}'."
);
}

/** @var \eZ\Publish\API\Repository\Values\Content\Query\SortClause\Target\MapLocationTarget $target */
Expand Down

0 comments on commit a352e62

Please sign in to comment.