Skip to content

Commit 50fcb2c

Browse files
committed
Show error message when vaas cannot actually connect
1 parent 3e24b10 commit 50fcb2c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Vaas/ScanClient.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Gdatacyberdefenseag\GdataAntivirus\Vaas;
44

55
use Gdatacyberdefenseag\GdataAntivirus\Infrastructure\FileSystem\IGdataAntivirusFileSystem;
6+
use Gdatacyberdefenseag\GdataAntivirus\PluginPage\AdminNotices;
67
use Psr\Log\LoggerInterface;
78
use VaasSdk\Vaas;
89
use VaasSdk\Authentication\ClientCredentialsGrantAuthenticator;
@@ -16,14 +17,27 @@ class ScanClient {
1617
private LoggerInterface $logger;
1718
private VaasOptions $vaas_options;
1819
private IGdataAntivirusFileSystem $file_system;
19-
20-
public function __construct( LoggerInterface $logger, VaasOptions $vaas_options, IGdataAntivirusFileSystem $file_system ) {
20+
private AdminNotices $admin_notices;
21+
22+
public function __construct(
23+
LoggerInterface $logger,
24+
VaasOptions $vaas_options,
25+
IGdataAntivirusFileSystem $file_system,
26+
AdminNotices $admin_notices
27+
) {
2128
$logger->info('ScanClient::__construct');
2229
$this->logger = $logger;
2330
$this->vaas_options = $vaas_options;
2431
$this->file_system = $file_system;
32+
$this->admin_notices = $admin_notices;
2533

26-
$this->Connect();
34+
try {
35+
$this->Connect();
36+
} catch (\Exception $e) {
37+
$this->admin_notices->add_notice($e->getMessage());
38+
$this->logger->error("VaaS connection failed. Please verify if the VaaS-Url is correct.");
39+
return;
40+
}
2741
$plugin_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_plugin_upload_scan_enabled', false);
2842
$media_upload_scan_enabled = (bool) \get_option('gdatacyberdefenseag_antivirus_options_on_demand_scan_media_upload_scan_enabled', false);
2943
// We don't need to add the filters if both plugin and media upload scan are disabled.

0 commit comments

Comments
 (0)