Skip to content

Commit be573a8

Browse files
committed
Fix and improve error handling 2
1 parent a9e85ec commit be573a8

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/OhDear.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function getCpNavItem(): ?array
158158

159159
private function registerWidgets(): void
160160
{
161-
if (! $this->settings->hasApiCredentials()) {
161+
if (! OhDear::$plugin->getSettings()->hasApiCredentials()) {
162162
return;
163163
}
164164

src/models/Settings.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class Settings extends Model
3232

3333
public string $pluginName = 'Oh Dear';
3434

35-
public string $apiToken = '';
35+
public ?string $apiToken = '';
3636

37-
public string $selectedSiteId = '';
37+
public ?string $selectedSiteId = '';
3838

3939
public bool $showNavBadges = false;
4040

@@ -63,12 +63,12 @@ public function hasApiCredentials(): bool
6363
! empty($this->getSelectedSiteId());
6464
}
6565

66-
public function getApiToken(): string
66+
public function getApiToken(): ?string
6767
{
6868
return App::parseEnv($this->apiToken);
6969
}
7070

71-
public function getSelectedSiteId(): string
71+
public function getSelectedSiteId(): ?string
7272
{
7373
return App::parseEnv($this->selectedSiteId);
7474
}

src/services/OhDearService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class OhDearService extends Component
5454
public function __construct($config = [])
5555
{
5656
parent::__construct($config);
57+
58+
if (! OhDear::$plugin->getSettings()->hasApiCredentials()) {
59+
throw new Exception('Please provide a valid API token and site ID in the Oh Dear plugin settings.');
60+
}
5761

5862
$this->monitorId = intval(OhDear::$plugin->getSettings()->getSelectedSiteId());
5963
$this->apiToken = OhDear::$plugin->getSettings()->getApiToken();

src/translations/de/ohdear.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
'Paste the secret from Oh Dear here.' => 'Fügen Sie das Secret von Oh Dear hier ein.',
137137
'Your Health Check endpoint is protected by this secret. You can find the secret on Oh Dear\'s {link} page. If you change it, make sure to change it in Oh Dear as well.' => 'Der Health-Check-Endpunkt ist durch dieses Secret gesichert. Sie können das Secret in Oh Dears {link} finden. Falls Sie es ändern, stellen Sie sicher, dass Sie es auch in Oh Dear anpassen.',
138138
'Please provide a valid API token and site ID.' => 'Bitte geben Sie zuerst einen API-Token und eine Site-ID ein.',
139+
'Please provide a valid API token and site ID in the Oh Dear plugin settings.' => 'Bitte geben Sie in den Oh Dear Plugin Einstellungen zuerst einen API-Token und eine Site-ID ein.',
139140
'performanceScore' => 'Performance',
140141
'accessibilityScore' => 'Accessibility',
141142
'bestPracticesScore' => 'Best Practices',

0 commit comments

Comments
 (0)