Skip to content

Commit 73eff2f

Browse files
committed
Catch error when credentials are empty.
1 parent e437738 commit 73eff2f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
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 (! $this->getSettings()->hasApiCredentials()) {
162162
return;
163163
}
164164

src/models/Settings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public function behaviors(): array
5555
*/
5656
public function hasApiCredentials(): bool
5757
{
58-
return ! empty($this->apiToken) && ! empty($this->selectedSiteId);
58+
return ! empty($this->apiToken) && ! empty($this->selectedSiteId) && ! empty($this->getApiToken()) && ! empty($this->getSelectedSiteId());
5959
}
6060

61-
public function getApiToken(): string
61+
public function getApiToken(): ?string
6262
{
6363
return App::parseEnv($this->apiToken);
6464
}
6565

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

src/services/OhDearService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class OhDearService extends Component
4949
public function __construct($config = [])
5050
{
5151
parent::__construct($config);
52+
53+
if (! OhDear::$plugin->getSettings()->hasApiCredentials()) {
54+
throw new Exception('Oh Dear credentials are not set. Please check your settings.');
55+
}
5256

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

0 commit comments

Comments
 (0)