Handle failing to fetch blog posts. Fixes #1878

This commit is contained in:
James Brooks
2016-06-03 14:00:23 +01:00
parent 715eb02844
commit c8b602d349
3 changed files with 17 additions and 8 deletions

View File

@@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Integrations;
use GuzzleHttp\Client;
use Exception;
use Illuminate\Contracts\Cache\Repository;
/**
@@ -63,12 +64,16 @@ class Feed
*/
public function entries()
{
return $this->cache->remember('feeds', 2880, function () {
$xml = simplexml_load_string((new Client())->get($this->url, [
'headers' => ['Accept' => 'application/rss+xml', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'],
])->getBody()->getContents(), null, LIBXML_NOCDATA);
return $this->cache->remember('feeds', 720, function () {
try {
$xml = simplexml_load_string((new Client())->get($this->url, [
'headers' => ['Accept' => 'application/rss+xml', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'],
])->getBody()->getContents(), null, LIBXML_NOCDATA);
return json_decode(json_encode($xml));
return json_decode(json_encode($xml));
} catch (Exception $e) {
// Do nothing, this isn't critical.
}
});
}
}