Skip to content

Commit

Permalink
Issue #56: Drop the numeric error codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
donquixote committed Dec 3, 2024
1 parent 85ec4a0 commit ce8d9a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
10 changes: 2 additions & 8 deletions src/Cool/CollaboraDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,12 @@ public function getWopiClientURL(string $mimetype = 'text/plain'): string {

$discovery_parsed = simplexml_load_string($xml);
if (!$discovery_parsed) {
throw new CollaboraNotAvailableException(
'The retrieved discovery.xml file is not a valid XML file.',
102,
);
throw new CollaboraNotAvailableException('The retrieved discovery.xml file is not a valid XML file.');
}

$result = $discovery_parsed->xpath(sprintf('/wopi-discovery/net-zone/app[@name=\'%s\']/action', $mimetype));
if (empty($result[0]['urlsrc'][0])) {
throw new CollaboraNotAvailableException(
'The requested mime type is not handled.',
103,
);
throw new CollaboraNotAvailableException('The requested mime type is not handled.');
}

return (string) $result[0]['urlsrc'][0];
Expand Down
19 changes: 6 additions & 13 deletions src/Cool/CollaboraDiscoveryFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public function getDiscoveryXml(): string {
]);
throw new CollaboraNotAvailableException(
'Not able to retrieve the discovery.xml file from the Collabora Online server.',
203,
$e,
previous: $e,
);
}
return $xml;
Expand All @@ -95,21 +94,15 @@ protected function getWopiClientServerBaseUrl(): string {
$cool_settings = $this->loadSettings();
$wopi_client_server = $cool_settings['server'] ?? NULL;
if (!$wopi_client_server) {
throw new CollaboraNotAvailableException(
'The configured Collabora Online server address is empty.',
201,
);
throw new CollaboraNotAvailableException('The configured Collabora Online server address is empty.');
}
$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(
sprintf(
"The configured Collabora Online server address must begin with 'http://' or 'https://'. Found '%s'.",
$wopi_client_server,
),
204,
);
throw new CollaboraNotAvailableException(sprintf(
"The configured Collabora Online server address must begin with 'http://' or 'https://'. Found '%s'.",
$wopi_client_server,
));
}

return $wopi_client_server;
Expand Down
1 change: 0 additions & 1 deletion tests/src/ExistingSite/FetchClientUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function testFetchClientUrlWithMisconfiguration(): void {

$this->expectException(CollaboraNotAvailableException::class);
$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 ce8d9a7

Please sign in to comment.