Проброс в запрос фида, обработка исключения для запроса API

parent 1f62ca14
......@@ -58,7 +58,7 @@ class Statistics
$dataRequest = array(
'method' => $type,
'data' => array(
'feed_id' => 10003,
'feed_id' => $feed_id_list[0],
'start_date' => $dates['start'],
'end_date' => $dates['end'],
)
......@@ -66,8 +66,14 @@ class Statistics
}
//return $dataRequest;
$stats = $this->apiRequest($dataRequest);
//$stats = $this->apiRequest($dataRequest);
try {
$stats = $this->apiRequest($dataRequest);
} catch (\Exception $e) {
$stats['status'] = 'Error';
}
//return $stats;
// В запросе ошибка или отсутствуют данные для статистики:
if ($stats['status'] == 'Error') {
......@@ -77,7 +83,6 @@ class Statistics
return null;
}
$dataStats = array();
$dataStats['report'] = $report_type;
......@@ -233,12 +238,6 @@ class Statistics
// Данные для отчета 'transaction':
if ($report_type == 'transaction') {
$dataStats['period'] = [];
$dataStats['Timestamp'] = [];
$dataStats['OrderSum'] = [];
$dataStats['Basket'] = [];
foreach ($stats['data'] as $item) {
$dataStats['period'][] = $item['ForeignID'];
$dataStats['Timestamp'][] = $item['Timestamp'];
......@@ -257,7 +256,7 @@ class Statistics
// Запрос к API:
private function apiRequest($data)
{
//return $data;
$playload = json_encode($data);
$url = 'http://stat.instraroam.net/json/'.md5($playload . $this->hashSolt);
......@@ -278,7 +277,6 @@ class Statistics
if($info['http_code'] != 200) {
throw new \Exception('Error. ' . $info['http_code']);
//throw new \Exception('Error. ' . $info['http_code'] . ' json-data: '. json_encode($data)); // для передачи данных json-запроса
}
return json_decode($result, 1);
......
......@@ -36,7 +36,7 @@ $this->headScript()
->appendFile('/js/script-feeds-stat-table.js')
->appendFile('/js/script-feeds-stat.js')
->appendFile('/js/adm/service-actions.js')
//->appendFile('/js/script-canvas.js')
;
$this->headLink()
......@@ -158,13 +158,6 @@ if (!$error) {
<div class="message"></div>
</div>
<?php /* ?>
<div>
<img id="scream" src="/img/canvas/image-test5.jpg" alt="The Scream" width="200" height="200">
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;"></canvas>
</div>
<?php */ ?>
<?php /* График */ ?>
<?php if ($current_report == 'common'): ?>
<div id="chart-graph-stat" style="height: 370px;" data-colors=<?= ($colors_active_lines ? json_encode($colors_active_lines) : '')?>></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment