chg: [internal] Log exception for remote server POST test

pull/7627/head
Jakub Onderka 2021-08-05 10:25:15 +02:00
parent 10b9dc4db3
commit 8dd8e58f5b
2 changed files with 15 additions and 5 deletions

View File

@ -128,6 +128,16 @@ class ServerSyncTool
return $response;
}
/**
* @param string $testString
* @return HttpSocketResponseExtended
* @throws Exception
*/
public function postTest($testString)
{
return $this->post('/servers/postTest', ['testString' => $testString]);
}
/**
* @param string $url
* @param mixed $data

View File

@ -2518,16 +2518,16 @@ class Server extends AppModel
if (!$testFile) {
throw new Exception("Could not load payload for POST test.");
}
$HttpSocket = $this->setupHttpSocket($server);
$request = $this->setupSyncRequest($server);
$uri = $server['Server']['url'] . '/servers/postTest';
$serverSync = new ServerSyncTool($server, $this->setupSyncRequest($server));
try {
$response = $HttpSocket->post($uri, json_encode(array('testString' => $testFile)), $request);
$response = $serverSync->postTest($testFile);
$contentEncoding = $response->getHeader('Content-Encoding');
$rawBody = $response->body;
$response = $this->jsonDecode($rawBody);
$response = $response->json();
} catch (Exception $e) {
$this->logException("Invalid response for remote server {$server['Server']['name']} POST test.", $e);
$title = 'Error: POST connection test failed. Reason: ' . $e->getMessage();
$this->loadLog()->createLogEntry('SYSTEM', 'error', 'Server', $server['Server']['id'], $title);
return ['status' => 8];