Skip to content

Commit

Permalink
Issue #56: Change exception messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
donquixote committed Dec 3, 2024
1 parent 4985c31 commit 88594bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/Cool/CollaboraDiscoveryFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,30 @@ protected function getWopiClientServerBaseUrl(): string {
$wopi_client_server = $cool_settings['server'] ?? NULL;
if (!$wopi_client_server) {
throw new CollaboraNotAvailableException(
'Collabora Online server address is not valid.',
'The configured Collabora Online server address is empty.',
201,
);
}
$wopi_client_server = trim($wopi_client_server);

if (!str_starts_with($wopi_client_server, 'http://') && !str_starts_with($wopi_client_server, 'https://')) {
throw new CollaboraNotAvailableException(
'Warning! You have to specify the scheme protocol too (http|https) for the server address.',
sprintf(
"The configured Collabora Online server address must begin with 'http://' or 'https://'. Found '%s'.",
$wopi_client_server,
),
204,
);
}

$host_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
if (!str_starts_with($wopi_client_server, $host_scheme . '://')) {
throw new CollaboraNotAvailableException(
'Collabora Online server address scheme does not match the current page url scheme.',
sprintf(
"The url scheme '%s' of the current request does not match the url scheme of the configured Collabora Online server address '%s'.",
$host_scheme,
$wopi_client_server,
),
202,
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/ExistingSite/FetchClientUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testFetchClientUrlWithMisconfiguration(): void {
$discovery = \Drupal::service(CollaboraDiscovery::class);

$this->expectException(CollaboraNotAvailableException::class);
$this->expectExceptionMessage('Warning! You have to specify the scheme protocol too (http|https) for the server address.');
$this->expectExceptionMessage("The configured Collabora Online server address must begin with 'http://' or 'https://'. Found 'httx://example.com'.");
$this->expectExceptionCode(204);

$discovery->getWopiClientURL();
Expand Down

0 comments on commit 88594bc

Please sign in to comment.