Skip to content

Commit 5088b91

Browse files
Merge pull request #49311 from nextcloud/fix/ocmdiscoveryservice/cache-errors
2 parents 1abe9de + cc8e69c commit 5088b91

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/private/OCM/OCMDiscoveryService.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
5555

5656
if (!$skipCache) {
5757
try {
58-
$this->provider->import(json_decode($this->cache->get($remote) ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []);
58+
$cached = $this->cache->get($remote);
59+
if ($cached === false) {
60+
throw new OCMProviderException('Previous discovery failed.');
61+
}
62+
63+
$this->provider->import(json_decode($cached ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []);
5964
if ($this->supportedAPIVersion($this->provider->getApiVersion())) {
6065
return $this->provider; // if cache looks valid, we use it
6166
}
@@ -85,8 +90,10 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
8590
$this->cache->set($remote, $body, 60 * 60 * 24);
8691
}
8792
} catch (JsonException|OCMProviderException $e) {
93+
$this->cache->set($remote, false, 5 * 60);
8894
throw new OCMProviderException('data returned by remote seems invalid - ' . ($body ?? ''));
8995
} catch (\Exception $e) {
96+
$this->cache->set($remote, false, 5 * 60);
9097
$this->logger->warning('error while discovering ocm provider', [
9198
'exception' => $e,
9299
'remote' => $remote
@@ -95,6 +102,7 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
95102
}
96103

97104
if (!$this->supportedAPIVersion($this->provider->getApiVersion())) {
105+
$this->cache->set($remote, false, 5 * 60);
98106
throw new OCMProviderException('API version not supported');
99107
}
100108

0 commit comments

Comments
 (0)