if ($xml !== FALSE && (isset($xml->ErrorNumber) || isset($xml->ErrorCode))) {
if ($isError) {
$error = '';
$error = ''; $code = 0;
$error_code = 0;
if (isset($xml->DetailedErrorDescription) && !empty($xml->DetailedErrorDescription)) {
if (isset($xml->DetailedErrorDescription) && !empty($xml->DetailedErrorDescription)) {
$error = (string) $xml->DetailedErrorDescription;
$error = (string) $xml->DetailedErrorDescription;
}
}
@ -517,20 +506,16 @@ class EBSCOConnector {
$error = (string) $xml->Reason;
$error = (string) $xml->Reason;
}
}
if (isset($xml->ErrorNumber)) {
if (isset($xml->ErrorNumber)) {
$code = (integer) $xml->ErrorNumber;
$error_code = (int) $xml->ErrorNumber;
}
}
elseif (isset($xml->ErrorCode)) {
elseif (isset($xml->ErrorCode)) {
$code = (integer) $xml->ErrorCode;
$error_code = (int) $xml->ErrorCode;
}
}
$return = new EBSCOException($error, $code);
$return = new EBSCOException($error, $error_code);
}
}
else {
else {
$return = new EBSCOException("HTTP {$code} : The request could not be understood by the server due to malformed syntax. Modify your search before retrying.");
$return = new EBSCOException("HTTP {$code} : The request could not be understood by the server due to malformed syntax. Modify your search before retrying.");
}
}
}
catch (Exception $e) {
$return = new EBSCOException($xml);
}
break;
break;
case self::HTTP_NOT_FOUND:
case self::HTTP_NOT_FOUND:
@ -545,20 +530,14 @@ class EBSCOConnector {
$return = new EBSCOException("HTTP {$code} : Unexpected HTTP error.");
$return = new EBSCOException("HTTP {$code} : Unexpected HTTP error.");
break;
break;
}
}
}
catch (Exception $e) {
// Or $this->toString($response)
$message = $this->toString($e);
\Drupal::logger('ebsco')->error($message);
$return = new EBSCOException($response);
}
// Log any error
if ($this->logAPIRequests) {
if ($this->logAPIRequests) {
// $client = both the HTTP request and response
\Drupal::logger('ebsco')->debug('EDS @method @url returned HTTP @code: @response', [
// $response = only the HTTP response
'@method' => $method,
$message = $this->toString($client); // or $this->toString($response)