fix: Better error handling when previewing csv/freetext feeds if no valid data is returned

pull/2831/head
iglocska 2018-01-13 15:36:27 +01:00
parent 995a1c700e
commit 56dc5ea3bc
2 changed files with 7 additions and 4 deletions

View File

@ -420,8 +420,9 @@ class FeedsController extends AppController {
// params is passed as reference here, the pagination happens in the method, which isn't ideal but considering the performance gains here it's worth it
$resultArray = $this->Feed->getFreetextFeed($feed, $HttpSocket, $feed['Feed']['source_format'], $currentPage, 60, $params);
// we want false as a valid option for the split fetch, but we don't want it for the preview
if ($resultArray == false) {
$resultArray = array();
if (!is_array($resultArray)) {
$this->Session->setFlash($resultArray);
$this->redirect(array('controller' => 'feeds', 'action' => 'index'));
}
$this->params->params['paging'] = array($this->modelClass => $params);
$resultArray = $this->Feed->getFreetextFeedCorrelations($resultArray, $feed['Feed']['id']);

View File

@ -216,16 +216,18 @@ class Feed extends AppModel {
$response = $this->__getRecursive($feed['Feed']['url'], '', array());
//$response = $HttpSocket->get($feed['Feed']['url'], '', array());
} catch (Exception $e) {
return false;
return $e->getMessage();
}
if ($response->code == 200) {
$redis = $this->setupRedis();
if ($redis === false) {
return false;
return 'Could not reach Redis.';
}
$redis->del('misp:feed_cache:' . $feed['Feed']['id']);
$data = $response->body;
file_put_contents($feedCache, $data);
} else {
return 'Invalid response code returned: ' . $response->code;
}
}
}