Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create try-catch block for index method #2724

Open
wants to merge 1 commit into
base: feature/TAO-10203-advanced-search
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion models/classes/search/tasks/UpdateResourceInIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace oat\tao\model\search\tasks;

use Exception;
use oat\generis\model\OntologyAwareTrait;
use oat\oatbox\action\Action;
use oat\tao\model\search\index\DocumentBuilder\IndexDocumentBuilder;
Expand Down Expand Up @@ -64,7 +65,11 @@ public function __invoke($params): Report
/** @var Search $searchService */
$searchService = $this->getServiceLocator()->get(Search::SERVICE_ID);

$numberOfIndexed = $searchService->index([$indexDocument]);
try {
$numberOfIndexed = $searchService->index([$indexDocument]);
} catch (Exception $exception) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT?

Suggested change
} catch (Exception $exception) {
} catch (Throwable $exception) {

return new Report(Report::TYPE_ERROR, $exception->getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use static method:

Suggested change
return new Report(Report::TYPE_ERROR, $exception->getMessage());
return Report::createFailure($exception->getMessage());

}

if ($numberOfIndexed === 0) {
$type = Report::TYPE_ERROR;
Expand Down