diff --git a/app/Http/Controllers/Dashboard/DashboardController.php b/app/Http/Controllers/Dashboard/DashboardController.php index ca3fdb52..1f7292c2 100644 --- a/app/Http/Controllers/Dashboard/DashboardController.php +++ b/app/Http/Controllers/Dashboard/DashboardController.php @@ -69,7 +69,7 @@ class DashboardController extends Controller $subscribers = $this->getSubscribers(); $entries = null; - if ($feed = $this->feed->entries()) { + if ($feed = $this->feed->latest()) { $entries = array_slice($feed->channel->item, 0, 5); } diff --git a/app/Integrations/Credits.php b/app/Integrations/Credits.php index 3056af07..2050fc1f 100644 --- a/app/Integrations/Credits.php +++ b/app/Integrations/Credits.php @@ -11,6 +11,7 @@ namespace CachetHQ\Cachet\Integrations; +use Exception; use GuzzleHttp\Client; use Illuminate\Contracts\Cache\Repository; @@ -23,6 +24,13 @@ class Credits */ const URL = 'https://cachethq.io/credits'; + /** + * The failed status indicator. + * + * @var int + */ + const FAILED = 1; + /** * The cache repository instance. * @@ -54,14 +62,20 @@ class Credits /** * Returns the latest credits. * - * @return array + * @return array|null */ public function latest() { - return $this->cache->remember('credits', 2880, function () { - return json_decode((new Client())->get($this->url, [ - 'headers' => ['Accept' => 'application/json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'], - ])->getBody(), true); + $result = $this->cache->remember('credits', 2880, function () { + try { + return json_decode((new Client())->get($this->url, [ + 'headers' => ['Accept' => 'application/json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'], + ])->getBody(), true); + catch (Exception $e) { + return self::FAILED; + } }); + + return $result === self::FAILED ? null : $result; } } diff --git a/app/Integrations/Feed.php b/app/Integrations/Feed.php index ee09ddd1..033839b2 100644 --- a/app/Integrations/Feed.php +++ b/app/Integrations/Feed.php @@ -29,6 +29,13 @@ class Feed */ const URL = 'https://blog.alt-three.com/tag/cachet/rss'; + /** + * The failed status indicator. + * + * @var int + */ + const FAILED = 1; + /** * The cache repository instance. * @@ -58,13 +65,13 @@ class Feed } /** - * Returns the entries. + * Returns the latest entries. * - * @return array + * @return array|null */ - public function entries() + public function latest() { - return $this->cache->remember('feeds', 720, function () { + $result = $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'], @@ -72,8 +79,10 @@ class Feed return json_decode(json_encode($xml)); } catch (Exception $e) { - // Do nothing, this isn't critical. + return self::FAILED; } }); + + return $result === self::FAILED ? null : $result; } } diff --git a/app/Integrations/Releases.php b/app/Integrations/Releases.php index 1c0ff64f..65cb67b7 100644 --- a/app/Integrations/Releases.php +++ b/app/Integrations/Releases.php @@ -23,6 +23,13 @@ class Releases */ const URL = 'https://api.github.com/repos/cachethq/cachet/releases/latest'; + /** + * The failed status indicator. + * + * @var int + */ + const FAILED = 1; + /** * The cache repository instance. *