Skip to content

Commit 83907b8

Browse files
committed
fix: better handling of news update failure
1 parent 5d7dd67 commit 83907b8

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

app/Domain/Notifications/Hxcontrollers/News.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Leantime\Domain\Notifications\Hxcontrollers;
44

55
use Illuminate\Contracts\Container\BindingResolutionException;
6+
use Illuminate\Support\Facades\Log;
67
use Leantime\Core\Controller\HtmxController;
78
use Leantime\Domain\Menu\Services\Menu;
89
use Leantime\Domain\Timesheets\Services\Timesheets;
@@ -34,11 +35,15 @@ public function init(\Leantime\Domain\Notifications\Services\News $newsService):
3435
public function get()
3536
{
3637

38+
$news = false;
3739
try {
3840
$news = $this->newsService->getLatest(session('userdata.id'));
3941

4042
} catch (\Exception $e) {
41-
report($e);
43+
Log::warning('Could not connect to news server');
44+
}
45+
46+
if ($news === false) {
4247
$news = 'Could not connect to news server';
4348
}
4449

app/Domain/Notifications/Services/News.php

+20-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Leantime\Domain\Notifications\Services {
44

5+
use Illuminate\Support\Facades\Log;
56
use Leantime\Core\Db\Db as DbCore;
67
use Leantime\Core\Language as LanguageCore;
78
use Leantime\Domain\Notifications\Repositories\Notifications as NotificationRepository;
@@ -46,9 +47,16 @@ public function __construct(
4647
public function getLatest(int $userId): false|\SimpleXMLElement
4748
{
4849

49-
$rss = $this->getFeed();
50+
try {
51+
$rss = $this->getFeed();
52+
} catch (\Exception $e) {
53+
Log::warning('Could not connect to news server.');
54+
Log::warning($e);
5055

51-
$latestGuid = strval($rss?->channel?->item[0]?->guid);
56+
return false;
57+
}
58+
59+
$latestGuid = (string) $rss?->channel?->item[0]?->guid;
5260
$this->settingService->saveSetting('usersettings.'.$userId.'.lastNewsGuid', strval($latestGuid));
5361

5462
// Todo: check last article the user read
@@ -60,13 +68,20 @@ public function getLatest(int $userId): false|\SimpleXMLElement
6068
public function hasNews(int $userId): bool
6169
{
6270

63-
$rss = $this->getFeed();
71+
try {
72+
$rss = $this->getFeed();
73+
} catch (\Exception $e) {
74+
Log::warning('Could not connect to news server.');
75+
Log::warning($e);
76+
77+
return false;
78+
}
6479

65-
$latestGuid = strval($rss?->channel?->item[0]?->guid);
80+
$latestGuid = (string) $rss?->channel?->item[0]?->guid;
6681

6782
$lastNewsGuid = $this->settingService->getSetting('usersettings.'.$userId.'.lastNewsGuid');
6883

69-
if ($lastNewsGuid == false) {
84+
if ($lastNewsGuid === false) {
7085
return true;
7186
}
7287

0 commit comments

Comments
 (0)