Skip to content

Commit

Permalink
[5.x] Avoid error when marketplace client returns null (#10996)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Oct 22, 2024
1 parent 030ef7b commit 9fe1412
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Marketplace/Marketplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ public function package($package, $version = null, $edition = null)
}

return Cache::rememberWithExpiration("marketplace-$uri", function () use ($uri) {
$fallback = [5 => null];

try {
return [60 => Client::get($uri)['data']];
if (! $response = Client::get($uri)) {
return $fallback;
}

return [60 => $response['data']];
} catch (RequestException $e) {
return [5 => null];
return $fallback;
}
});
}
Expand All @@ -33,10 +39,16 @@ public function releases($package)
$uri = "packages/$package/releases";

return Cache::rememberWithExpiration("marketplace-$uri", function () use ($uri) {
$fallback = [5 => collect()];

try {
return [60 => collect(Client::get($uri)['data'])];
if (! $response = Client::get($uri)) {
return $fallback;
}

return [60 => collect($response['data'])];
} catch (RequestException $e) {
return [5 => collect()];
return $fallback;
}
});
}
Expand Down

0 comments on commit 9fe1412

Please sign in to comment.