diff --git a/src/NewsWidget.php b/src/NewsWidget.php index 3f4a9cb..5b995dd 100644 --- a/src/NewsWidget.php +++ b/src/NewsWidget.php @@ -38,6 +38,7 @@ protected function run(array $params = []): ?string $news = $this->getNews(); try { + if (isset($news['information'])) { $currentItem = $news['information']; } else { @@ -51,12 +52,12 @@ protected function run(array $params = []): ?string 'datechanged' => $currentItem['modifiedAt'], 'datefetched' => date('Y-m-d H:i:s'), ]; - } catch (\Throwable $e) { + } catch (\Exception $e) { $context = [ 'type' => 'error', 'title' => 'Unable to fetch news!', 'link' => '', - 'news' => '

Invalid JSON feed returned by ' . $this->source . '

' . $e->getMessage() . ' ', + 'news' => "

Invalid JSON feed returned by " . $this->source . "

" . $e->getMessage() . " ", ]; } @@ -73,7 +74,8 @@ private function getNews(): array try { $client = HttpClient::create(); $fetchedNewsData = $client->request('GET', $this->source, $options)->getContent(); - } catch (\Throwable $e) { + } catch (\Exception $e) { + $message = Str::shyphenate(preg_replace('/hash=[a-z0-9\%]+/i', '', $e->getMessage())); return [ @@ -81,7 +83,7 @@ private function getNews(): array 'type' => 'error', 'fieldValues' => [ 'title' => 'Unable to fetch news!', - 'content' => '

Unable to connect to ' . $this->source . '

' . $message . ' ', + 'content' => "

Unable to connect to " . $this->source . "

" . $message . " ", 'link' => null, ], 'modifiedAt' => '0000-01-01 00:00:00', @@ -118,7 +120,7 @@ private function getNews(): array 'type' => 'error', 'fieldValues' => [ 'title' => 'Unable to fetch news!', - 'content' => '

Unable to parse JSON from ' . $this->source . '

', + 'content' => "

Unable to parse JSON from " . $this->source . "

", 'link' => null, ], 'modifiedAt' => '0000-01-01 00:00:00',