Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bolt/newswidget
Browse files Browse the repository at this point in the history
  • Loading branch information
bobdenotter committed Jan 29, 2020
2 parents 3b2fd6b + 99cd012 commit 533d8f0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/NewsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function run(array $params = []): ?string
$news = $this->getNews();

try {

if (isset($news['information'])) {
$currentItem = $news['information'];
} else {
Expand All @@ -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' => '<p>Invalid JSON feed returned by <code>' . $this->source . '</code></p><small>' . $e->getMessage() . ' </small>',
'news' => "<p>Invalid JSON feed returned by <code>" . $this->source . "</code></p><small>" . $e->getMessage() . " </small>",
];
}

Expand All @@ -73,15 +74,16 @@ 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 [
'error' => [
'type' => 'error',
'fieldValues' => [
'title' => 'Unable to fetch news!',
'content' => '<p>Unable to connect to ' . $this->source . '</p><small>' . $message . ' </small>',
'content' => "<p>Unable to connect to " . $this->source . "</p><small>" . $message . " </small>",
'link' => null,
],
'modifiedAt' => '0000-01-01 00:00:00',
Expand Down Expand Up @@ -118,7 +120,7 @@ private function getNews(): array
'type' => 'error',
'fieldValues' => [
'title' => 'Unable to fetch news!',
'content' => '<p>Unable to parse JSON from ' . $this->source . '</p>',
'content' => "<p>Unable to parse JSON from " . $this->source . "</p>",
'link' => null,
],
'modifiedAt' => '0000-01-01 00:00:00',
Expand Down

0 comments on commit 533d8f0

Please sign in to comment.