From dd66b534f06143f1744936702466a43493bee4f0 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 6 Aug 2014 14:31:42 -0400 Subject: [PATCH] Smarter error handling. --- .../src/VuFindSearch/Backend/EDS/Backend.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Backend.php b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Backend.php index 37194defb7b..8edbaa1e48f 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Backend.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Backend.php @@ -270,7 +270,7 @@ class Backend extends AbstractBackend try { $authenticationToken = $this->getAuthenticationToken(); // check to see if the profile is overriden - $overrideProfile = $params->get('profile'); + $overrideProfile = (null !== $params) ? $params->get('profile') : null; if (isset($overrideProfile)) { $this->profile = $overrideProfile; } @@ -288,16 +288,26 @@ class Backend extends AbstractBackend $an, $dbId, $authenticationToken, $sessionToken, $hlTerms ); } catch (\EbscoEdsApiException $e) { - if ($e->getApiErrorCode() == 104) { + // if the auth or session token was invalid, try once more + switch ($e->getApiErrorCode()) { + case 104: + case 108: + case 109: try { - $authenticationToken = $this->getAuthenticationToken(true); + // For error 104, retry auth token; for 108/9, retry sess token: + if ($e->getApiErrorCode() == 104) { + $authenticationToken = $this->getAuthenticationToken(true); + } else { + $sessionToken = $this->getSessionToken(true); + } $response = $this->client->retrieve( $an, $dbId, $authenticationToken, $sessionToken, $hlTerms ); } catch(Exception $e) { throw new BackendException($e->getMessage(), $e->getCode(), $e); } - } else { + break; + default: throw $e; } } -- GitLab