Skip to content
Snippets Groups Projects
Commit 75c34e2a authored by Robert Lange's avatar Robert Lange
Browse files

refs #19158 [finc] undo refactoring in DocumentDeliveryServiceController

* but catching of error still  needs to be optimized
parent 5aae91f2
Branches
Tags
No related merge requests found
......@@ -281,7 +281,15 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase
->send();
if (!$response->isSuccess()) {
$this->throwErrorMessage($response);
if ($response->getContent()) {
$responseArray = $this->parseJsonAsArray($response->getContent());
if (array_key_exists('error', $responseArray)) {
$message = $responseArray['error'];
}
} else {
$message = 'HTTP status ' . $response->getStatusCode() . ' received';
}
throw new DDSException($message);
}
$responseArray = $this->parseJsonAsArray($response->getBody());
......@@ -577,23 +585,6 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase
);
}
}
/**
* @param \Zend\Http\Response $response
* @throws DDSException
*/
protected function throwErrorMessage(\Zend\Http\Response $response): void
{
$message = 'HTTP status ' . $response->getStatusCode() . ' received';
if ($response->getContent()) {
$responseArray = $this->parseJsonAsArray($response->getContent());
if ($responseArray && array_key_exists('error', $responseArray)) {
$message = $responseArray['error'];
}
}
throw new DDSException($message);
}
/**
* Retrieve data after successful sending previous record. Beware and keep
......@@ -971,8 +962,17 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase
);
exit;
}
$responseArray = $this->parseJsonAsArray($response->getContent());
if ($responseArray !== null && array_key_exists('error', $responseArray)) {
$message = $responseArray['error'];
}
} else {
$message = 'HTTP status ' . $response->getStatusCode() . ' received';
}
if (!empty($message)) {
throw new DDSException($message);
}
$this->throwErrorMessage($response);
}
return $this->parseJsonAsArray($response->getBody());
......@@ -1026,7 +1026,15 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase
->send();
if (!$response->isSuccess()) {
$this->throwErrorMessage($response);
if ($response->getContent()) {
$responseArray = $this->parseJsonAsArray($response->getContent());
if (array_key_exists('error', $responseArray)) {
$message = $responseArray['error'];
}
} else {
$message = 'HTTP status ' . $response->getStatusCode() . ' received';
}
throw new DDSException($message);
}
$responseArray = $this->parseJsonAsArray($response->getBody());
......
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