From fa4fe4067408da55ca8ea28bff94b71659d69966 Mon Sep 17 00:00:00 2001 From: Robert Lange <robert.lange@uni-leipzig.de> Date: Tue, 21 Sep 2021 16:12:29 +0200 Subject: [PATCH] refs #19158 [finc] dds mapping in zend-form: fix error handling (e.g. 401) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * also set input division (fakultät) required in dds-form.php --- module/finc/config/dds-form.php | 2 +- .../DocumentDeliveryServiceController.php | 48 ++++++++----------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/module/finc/config/dds-form.php b/module/finc/config/dds-form.php index 25bc048be9e..1fcb1903776 100644 --- a/module/finc/config/dds-form.php +++ b/module/finc/config/dds-form.php @@ -105,7 +105,7 @@ return [ 'empty_option' => '', ], 'attributes' => [ - 'required' => false, + 'required' => true, 'id' => 'division', ], ], diff --git a/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php b/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php index 23d91a76fd2..6d5f2b51482 100644 --- a/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php +++ b/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php @@ -281,15 +281,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase ->send(); if (!$response->isSuccess()) { - 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); + $this->throwErrorMessage($response); } $responseArray = $this->parseJsonAsArray($response->getBody()); @@ -585,6 +577,23 @@ 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 @@ -962,17 +971,8 @@ 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,15 +1026,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase ->send(); if (!$response->isSuccess()) { - 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); + $this->throwErrorMessage($response); } $responseArray = $this->parseJsonAsArray($response->getBody()); -- GitLab