Skip to content

Commit

Permalink
Fixed Askews and Holts SUSHI import issue #ERM-119
Browse files Browse the repository at this point in the history
  • Loading branch information
sumbria committed Mar 18, 2024
1 parent 6d288d5 commit 082177d
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions usage/admin/classes/domain/SushiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ private function jsonTransfer($reportLayout, $serviceProvider)
$trailingSlash = substr($this->serviceURL, -1) == '/' ? '' : '/';
$endpoint = $this->serviceURL . $trailingSlash . 'reports/' . strtolower($reportLayout) . '?' . http_build_query($params);
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
if ($this->security) {
if (preg_match("/http/i", $this->security)) {
curl_setopt($ch, CURLOPT_USERPWD, $this->login . ":" . $this->password);
Expand All @@ -397,28 +400,18 @@ private function jsonTransfer($reportLayout, $serviceProvider)
$this->log("Connecting to $this->serviceURL");

// try executing curl
try {
$response = curl_exec($ch);
} catch (Exception $e) {
$error = $e->getMessage();
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
$this->logStatus("Exception performing curl request with connection to $serviceProvider: $error");
$this->saveLogAndExit($reportLayout);
}

// check for curl errors
if (curl_errno($ch)) {
$this->logStatus("Request Error with connection to $serviceProvider:" . curl_error($ch));
$this->saveLogAndExit($reportLayout);
}
curl_close($ch);


// Check for errors
try {
$json = json_decode($response);
} catch (Exception $e) {
$error = $e->getMessage();
$this->logStatus("There was an error trying to parse the SUSHI report from $serviceProvider. This could be due to a malformed response from the sushi service. Error: $error");
$response = mb_convert_encoding($response, 'UTF-8', 'UTF-8');
$json = json_decode($response);
if (json_last_error() !== JSON_ERROR_NONE) {
$this->logStatus('JSON decoding error: ' . json_last_error_msg());
$this->saveLogAndExit($reportLayout);
}

Expand Down

0 comments on commit 082177d

Please sign in to comment.