Throw exceptions on error, check that we have results and always close the curl connection.
This commit is contained in:
parent
0ceacf6390
commit
a603d3e75f
1 changed files with 13 additions and 8 deletions
|
@ -13,22 +13,27 @@ class LBRY
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['method' => $function, 'params' => $params]));
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['method' => $function, 'params' => $params]));
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
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);
|
$responseData = json_decode($serverOutput, true);
|
||||||
return $responseData['result'];
|
|
||||||
|
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)
|
public static function findTopPublicFreeClaim($name)
|
||||||
{
|
{
|
||||||
$claims = LBRY::api('claim_list', ['name' => $name]);
|
$claims = LBRY::api('claim_list', ['name' => $name]);
|
||||||
|
|
||||||
if (!$claims || !isset($claims['claims']))
|
if (!$claims || !isset($claims['claims']))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue