move exec_curl_request from functions to MatrixConnection

This commit is contained in:
2018-02-23 18:27:58 +01:00
parent a51f44c01b
commit 076138a0a4
2 changed files with 40 additions and 47 deletions

View File

@@ -10,42 +10,4 @@ function abort($msg="Unknown")
print("\n");
exit();
}
function exec_curl_request($handle)
{
$response = curl_exec($handle);
if ($response === false) {
$errno = curl_errno($handle);
$error = curl_error($handle);
error_log("Curl returned error $errno: $error\n");
curl_close($handle);
return false;
}
$http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
curl_close($handle);
if ($http_code >= 500) {
// do not want to DDOS server if something goes wrong
sleep(10);
return false;
} else if ($http_code != 200) {
$response = json_decode($response, true);
error_log("Request has failed with error {$response['error']}\n");
if ($http_code == 401) {
throw new Exception('Invalid access token provided');
}
throw new Exception("Server responds: '" . $response['error'] . "'");
} else {
$response = json_decode($response, true);
if (isset($response["event_id"])) {
$response = true;
} else {
$response = false;
}
}
return $response;
}
?>