Skip to content
Snippets Groups Projects
Commit e487ec6b authored by David Maus's avatar David Maus
Browse files

Catch BackendException, trigger error event & rethrow

* VuFindSearch/Service.php (search, retrieve,
  retrieveBatch) (similar): Catch BackendException, trigger error
  event & rethrow.
parent f9e7fa60
No related merge requests found
...@@ -31,6 +31,7 @@ namespace VuFindSearch; ...@@ -31,6 +31,7 @@ namespace VuFindSearch;
use VuFindSearch\Backend\BackendInterface; use VuFindSearch\Backend\BackendInterface;
use VuFindSearch\Feature\RetrieveBatchInterface; use VuFindSearch\Feature\RetrieveBatchInterface;
use VuFindSearch\Backend\Exception\BackendException;
use Zend\Log\LoggerInterface; use Zend\Log\LoggerInterface;
use Zend\EventManager\EventManagerInterface; use Zend\EventManager\EventManagerInterface;
...@@ -100,7 +101,12 @@ class Service ...@@ -100,7 +101,12 @@ class Service
$args['backend_instance'] = $backend; $args['backend_instance'] = $backend;
$this->triggerPre($backend, $args); $this->triggerPre($backend, $args);
$response = $backend->search($query, $offset, $limit, $params); try {
$response = $backend->search($query, $offset, $limit, $params);
} catch (BackendException $e) {
$this->triggerError($e, $args);
throw $e;
}
$this->triggerPost($response, $args); $this->triggerPost($response, $args);
return $response; return $response;
} }
...@@ -123,7 +129,12 @@ class Service ...@@ -123,7 +129,12 @@ class Service
$args['backend_instance'] = $backend; $args['backend_instance'] = $backend;
$this->triggerPre($backend, $args); $this->triggerPre($backend, $args);
$response = $backend->retrieve($id, $params); try {
$response = $backend->retrieve($id, $params);
} catch (BackendException $e) {
$this->triggerError($e, $args);
throw $e;
}
$this->triggerPost($response, $args); $this->triggerPost($response, $args);
return $response; return $response;
} }
...@@ -151,11 +162,21 @@ class Service ...@@ -151,11 +162,21 @@ class Service
// all the records at once; otherwise, we need to load them one at a // all the records at once; otherwise, we need to load them one at a
// time and aggregate them: // time and aggregate them:
if ($backend instanceof RetrieveBatchInterface) { if ($backend instanceof RetrieveBatchInterface) {
$response = $backend->retrieveBatch($ids, $params); try {
$response = $backend->retrieveBatch($ids, $params);
} catch (BackendException $e) {
$this->triggerError($e, $args);
throw $e;
}
} else { } else {
$response = false; $response = false;
foreach ($ids as $id) { foreach ($ids as $id) {
$next = $backend->retrieve($id, $params); try {
$next = $backend->retrieve($id, $params);
} catch (BackendException $e) {
$this->triggerError($e, $args);
throw $e;
}
if (!$response) { if (!$response) {
$response = $next; $response = $next;
} else { } else {
...@@ -186,7 +207,12 @@ class Service ...@@ -186,7 +207,12 @@ class Service
$args['backend_instance'] = $backend; $args['backend_instance'] = $backend;
$this->triggerPre($backend, $args); $this->triggerPre($backend, $args);
$response = $backend->similar($id, $params); try {
$response = $backend->similar($id, $params);
} catch (BackendException $e) {
$this->triggerError($e, $args);
throw $e;
}
$this->triggerPost($response, $args); $this->triggerPost($response, $args);
return $response; return $response;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment