Skip to content
Snippets Groups Projects
Commit 381bfaa0 authored by Ere Maijala's avatar Ere Maijala Committed by Robert Lange
Browse files

Add logging.

parent b1cb46a3
No related merge requests found
...@@ -40,9 +40,11 @@ use Zend\Http\Headers; ...@@ -40,9 +40,11 @@ use Zend\Http\Headers;
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:ils_drivers Wiki * @link https://vufind.org/wiki/development:plugins:ils_drivers Wiki
*/ */
class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface,
\Zend\Log\LoggerAwareInterface
{ {
use \VuFindHttp\HttpServiceAwareTrait; use \VuFindHttp\HttpServiceAwareTrait;
use \VuFind\Log\LoggerAwareTrait;
use CacheTrait; use CacheTrait;
/** /**
...@@ -131,6 +133,7 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface ...@@ -131,6 +133,7 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
$result = null; $result = null;
$statusCode = null; $statusCode = null;
$returnValue = null; $returnValue = null;
$startTime = microtime(true);
try { try {
// Set API key if it is not already available in the GET params // Set API key if it is not already available in the GET params
...@@ -173,27 +176,48 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface ...@@ -173,27 +176,48 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
// Execute HTTP call // Execute HTTP call
$result = $client->send(); $result = $client->send();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logError("$method request for $url failed: " . $e->getMessage());
throw new ILSException($e->getMessage()); throw new ILSException($e->getMessage());
} }
$duration = round(microtime(true) - $startTime, 4);
$urlParams = $client->getRequest()->getQuery()->toString();
$code = $result->getStatusCode();
$this->debug(
"[$duration] $method request for $url?$urlParams results ($code):\n"
. $result->getBody()
);
// Get the HTTP status code // Get the HTTP status code
$statusCode = $result->getStatusCode(); $statusCode = $result->getStatusCode();
// Check for error // Check for error
if ($result->isServerError()) { if ($result->isServerError()) {
$this->logError(
"$method request for $url failed, HTTP error code: $statusCode"
);
throw new ILSException('HTTP error code: ' . $statusCode, $statusCode); throw new ILSException('HTTP error code: ' . $statusCode, $statusCode);
} }
$answer = $result->getBody(); $answer = $result->getBody();
$answer = str_replace('xmlns=', 'ns=', $answer); $answer = str_replace('xmlns=', 'ns=', $answer);
$xml = simplexml_load_string($answer); try {
$xml = simplexml_load_string($answer);
} catch (\Exception $e) {
$this->logError(
"Could not parse response for $method request for $url: "
. $e->getMessage() . ". Response was:\n"
. $result->getHeaders()->toString()
. "\n\n$answer"
);
throw new ILSException($e->getMessage());
}
if ($result->isSuccess()) { if ($result->isSuccess()) {
if (!$xml && $result->isServerError()) { if (!$xml && $result->isServerError()) {
throw new ILSException( $error = 'XML is not valid or HTTP error, URL: ' . $url .
'XML is not valid or HTTP error, URL: ' . $url . ', HTTP status code: ' . $statusCode;
', HTTP status code: ' . $statusCode, $statusCode $this->logError($error);
); throw new ILSException($error, $statusCode);
} }
$returnValue = $xml; $returnValue = $xml;
} else { } else {
...@@ -205,8 +229,10 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface ...@@ -205,8 +229,10 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
$result->getBody() . '. HTTP status code: ' . $statusCode $result->getBody() . '. HTTP status code: ' . $statusCode
); );
throw new ILSException( throw new ILSException(
'Alma error message: ' . $almaErrorMsg . ' | HTTP error code: ' . "Alma error message for $method request for $url: "
$statusCode, $statusCode . $almaErrorMsg . ' | HTTP error code: '
. $statusCode,
$statusCode
); );
} }
......
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