From e487ec6bf7e9d5225ed3418e70fd6ccd9b071f4e Mon Sep 17 00:00:00 2001 From: David Maus <maus@hab.de> Date: Mon, 13 May 2013 16:29:10 +0200 Subject: [PATCH] Catch BackendException, trigger error event & rethrow * VuFindSearch/Service.php (search, retrieve, retrieveBatch) (similar): Catch BackendException, trigger error event & rethrow. --- .../VuFindSearch/src/VuFindSearch/Service.php | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/module/VuFindSearch/src/VuFindSearch/Service.php b/module/VuFindSearch/src/VuFindSearch/Service.php index e4d2dc11d04..d8a0b7ecdb7 100644 --- a/module/VuFindSearch/src/VuFindSearch/Service.php +++ b/module/VuFindSearch/src/VuFindSearch/Service.php @@ -31,6 +31,7 @@ namespace VuFindSearch; use VuFindSearch\Backend\BackendInterface; use VuFindSearch\Feature\RetrieveBatchInterface; +use VuFindSearch\Backend\Exception\BackendException; use Zend\Log\LoggerInterface; use Zend\EventManager\EventManagerInterface; @@ -100,7 +101,12 @@ class Service $args['backend_instance'] = $backend; $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); return $response; } @@ -123,7 +129,12 @@ class Service $args['backend_instance'] = $backend; $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); return $response; } @@ -151,11 +162,21 @@ class Service // all the records at once; otherwise, we need to load them one at a // time and aggregate them: 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 { $response = false; 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) { $response = $next; } else { @@ -186,7 +207,12 @@ class Service $args['backend_instance'] = $backend; $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); return $response; } -- GitLab