1
0
mirror of synced 2024-11-21 21:06:07 +03:00

Error handling added

This commit is contained in:
kruglov 2013-07-03 11:34:39 +04:00
parent df7259e990
commit 9a04be2d9a

View File

@ -30,6 +30,8 @@ class IntaroCrmRestApi
protected $apiUrl;
protected $apiKey;
protected $apiVersion = '1';
protected $lastError;
protected $statusCode;
/**
* @param string $crmUrl - адрес CRM
@ -41,6 +43,22 @@ class IntaroCrmRestApi
$this->apiKey = $apiKey;
}
public function getStatusCode()
{
return $this->statusCode;
}
public function getLastError()
{
return $this->statusCode . ' ' . $this->lastError;
}
public function getLastErrorMessage()
{
return $this->lastError;
}
/* Методы для работы с заказами */
/**
* Получение заказа по id
@ -357,13 +375,27 @@ class IntaroCrmRestApi
}
$response = curl_exec($ch);
$this->statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch))
{
$this->lastError = 'Curl error: ' . curl_error($ch);
return null;
}
curl_close($ch);
if (empty($response))
return false;
$result = (array)json_decode($response, true);
return $result;
if ($result['success'] == false)
{
$this->lastError = $result['errorMsg'];
return null;
}
$this->lastError = null;
unset($result['success']);
if (count($result) == 0)
return true;
return reset($result);
}
}