Throw exceptions on error, check that we have results and always close the curl connection.

This commit is contained in:
Filip Hendrik 2017-03-30 02:13:20 +02:00
parent 0ceacf6390
commit a603d3e75f

View file

@ -13,22 +13,27 @@ class LBRY
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['method' => $function, 'params' => $params]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
$serverOutput = curl_exec($ch);
curl_close($ch);
if ($server_output)
if ($serverOutput)
{
$responseData = json_decode($server_output, true);
return $responseData['result'];
$responseData = json_decode($serverOutput, true);
if (isset($responseData['error'])) {
throw new Exception($responseData['error']);
}
if (isset($responseData['result'])) {
return $responseData['result'];
}
}
curl_close ($ch);
return $server_output;
}
public static function findTopPublicFreeClaim($name)
{
$claims = LBRY::api('claim_list', ['name' => $name]);
if (!$claims || !isset($claims['claims']))
{
return null;