Skip to content

Commit 62fc990

Browse files
Merge pull request #49470 from nextcloud/backport/49311/stable28
2 parents 4260dd1 + 8d97e75 commit 62fc990

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
@@ -72,7 +72,12 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
7272

7373
if (!$skipCache) {
7474
try {
75-
$this->provider->import(json_decode($this->cache->get($remote) ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []);
75+
$cached = $this->cache->get($remote);
76+
if ($cached === false) {
77+
throw new OCMProviderException('Previous discovery failed.');
78+
}
79+
80+
$this->provider->import(json_decode($cached ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []);
7681
if ($this->supportedAPIVersion($this->provider->getApiVersion())) {
7782
return $this->provider; // if cache looks valid, we use it
7883
}
@@ -99,8 +104,10 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
99104
$this->cache->set($remote, $body, 60 * 60 * 24);
100105
}
101106
} catch (JsonException|OCMProviderException $e) {
107+
$this->cache->set($remote, false, 5 * 60);
102108
throw new OCMProviderException('data returned by remote seems invalid - ' . ($body ?? ''));
103109
} catch (\Exception $e) {
110+
$this->cache->set($remote, false, 5 * 60);
104111
$this->logger->warning('error while discovering ocm provider', [
105112
'exception' => $e,
106113
'remote' => $remote
@@ -109,6 +116,7 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
109116
}
110117

111118
if (!$this->supportedAPIVersion($this->provider->getApiVersion())) {
119+
$this->cache->set($remote, false, 5 * 60);
112120
throw new OCMProviderException('API version not supported');
113121
}
114122

0 commit comments

Comments
 (0)