Skip to content

Commit e68a63c

Browse files
committed
fix(ocm-discovery): improve error handling
- Prevent undefined variable access when response is missing. Signed-off-by: Micke Nordin <[email protected]>
1 parent 0cad579 commit e68a63c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/private/OCM/OCMDiscoveryService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ public function discover(string $remote, bool $skipCache = false): ICapabilityAw
110110

111111
foreach ($urls as $url) {
112112
$body = null;
113+
$status = null;
113114
try {
114115
$response = $client->get($url, $options);
115116
if ($response->getStatusCode() === Http::STATUS_OK) {
116117
$body = $response->getBody();
118+
$status = $response->getStatusCode();
117119
// update provider with data returned by the request
118120
$provider->import(json_decode($body, true, 8, JSON_THROW_ON_ERROR) ?? []);
119121
$this->cache->set($remote, $body, 60 * 60 * 24);
@@ -133,7 +135,7 @@ public function discover(string $remote, bool $skipCache = false): ICapabilityAw
133135
throw new OCMProviderException('invalid remote ocm endpoint');
134136
} catch (JsonException|OCMProviderException) {
135137
$this->cache->set($remote, false, 5 * 60);
136-
throw new OCMProviderException('data returned by remote seems invalid - status:' . $response->getStatusCode() . ' - ' . ($body ?? ''));
138+
throw new OCMProviderException('data returned by remote seems invalid - status: ' . ($status ?? '') . ' - body: ' . ($body ?? ''));
137139
} catch (\Exception $e) {
138140
$this->cache->set($remote, false, 5 * 60);
139141
$this->logger->warning('error while discovering ocm provider', [

0 commit comments

Comments
 (0)