From 9e3c63663605bd971dc619c29321938e2ed1b9ab Mon Sep 17 00:00:00 2001 From: Tadasu Isogawa Date: Wed, 7 Dec 2022 16:10:44 +0900 Subject: [PATCH] Throw Kount_Ris_Exception on error from API --- src/Kount/Ris/Request.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Kount/Ris/Request.php b/src/Kount/Ris/Request.php index 2981d1a..fceb869 100644 --- a/src/Kount/Ris/Request.php +++ b/src/Kount/Ris/Request.php @@ -340,12 +340,9 @@ public function getResponse() $this->logger->debug(__METHOD__ . " Posting to RIS"); // Call the RIS server and get the response $output = curl_exec($ch); - - if (curl_errno($ch)) { - $result = curl_error($ch); - $this->logger->error(__METHOD__ . " An error occurred posting to RIS. " . - "Curl error [$result]"); - } + $curlErrNo = curl_errno($ch); + $curlError = curl_error($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $time = microtime(true) - $startTimer; @@ -358,6 +355,19 @@ public function getResponse() $this->logger->debug(__METHOD__ . " Raw RIS response:\n {$output}"); + if ($curlErrNo || $httpCode >= 400) { + $errorMessage = 'An error occurred posting to RIS.'; + if ($curlErrNo) { + $errorMessage .= " Curl error [$curlError]"; + $errorCode = $curlErrNo; + } else { + $errorMessage .= " HTTP code [$httpCode]"; + $errorCode = $httpCode; + } + $this->logger->error(__METHOD__ . " $errorMessage"); + throw new Kount_Ris_Exception($errorMessage, $errorCode); + } + return new Kount_Ris_Response($output); } //end getResponse