From 2ae5b8cd5c7a5d03a3fae3d1f868ba42aa022472 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Mon, 9 Jul 2018 12:28:56 -0400 Subject: [PATCH] Further refinement of exception handling. --- .../VuFindSearch/Backend/Solr/Connector.php | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Connector.php index 50ba704fa1a..40ecab813b4 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Connector.php @@ -34,8 +34,9 @@ use InvalidArgumentException; use VuFindSearch\Backend\Exception\BackendException; use VuFindSearch\Backend\Exception\HttpErrorException; - +use VuFindSearch\Backend\Exception\RemoteErrorException; use VuFindSearch\Backend\Exception\RequestErrorException; + use VuFindSearch\Backend\Solr\Document\AbstractDocument; use VuFindSearch\ParamBag; @@ -377,6 +378,24 @@ class Connector implements \Zend\Log\LoggerAwareInterface || $ex instanceof RequestErrorException; } + /** + * If an unexpected exception type was received, wrap it in a generic + * BackendException to standardize upstream handling. + * + * @param \Exception $ex Exception + */ + protected function forceToBackendException($ex) + { + // Don't wrap specific backend exceptions.... + if ($ex instanceof RemoteErrorException + || $ex instanceof RequestErrorException + || $ex instanceof HttpErrorException + ) { + return $ex; + } + return new BackendException('Problem connecting to Solr.', null, $ex); + } + /** * Try all Solr URLs until we find one that works (or throw an exception). * @@ -405,7 +424,7 @@ class Connector implements \Zend\Log\LoggerAwareInterface return $this->send($client); } catch (\Exception $ex) { if ($this->isRethrowableSolrException($ex)) { - throw $ex; + throw $this->forceToBackendException($ex); } $exception = $ex; } @@ -413,7 +432,7 @@ class Connector implements \Zend\Log\LoggerAwareInterface // If we got this far, everything failed -- throw a BackendException with // the most recent exception caught above set as the previous exception. - throw new BackendException('Problem connecting to Solr.', null, $exception); + throw $this->forceToBackendException($exception); } /** -- GitLab