Skip to content

Commit 58a5d36

Browse files
authored
[Chrore] Handle speedtest.net not reachable gracefully. (#2313)
1 parent 377533d commit 58a5d36

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/Actions/GetOoklaSpeedtestServers.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ class GetOoklaSpeedtestServers
1717
*/
1818
public function handle(): array
1919
{
20-
return collect(self::fetch())->mapWithKeys(function (array $item) {
20+
$servers = self::fetch();
21+
22+
// If the first item is not an array, treat as error or empty
23+
if (empty($servers) || ! is_array($servers) || (isset($servers[0]) && ! is_array($servers[0]))) {
24+
// Return error message as a single option so user can see the error
25+
return ['error' => $servers[0] ?? 'Unable to retrieve servers'];
26+
}
27+
28+
return collect($servers)->mapWithKeys(function (array $item) {
2129
return [
2230
$item['id'] => ($item['sponsor'] ?? 'Unknown').' ('.($item['name'] ?? 'Unknown').', '.$item['id'].')',
2331
];

0 commit comments

Comments
 (0)