Online features need a stable connection. These steps resolve most connectivity errors.
Toggle Wi-Fi/mobile data off and on.
Switch between Wi-Fi and mobile data to isolate the problem.
Restart your router if on Wi-Fi.
Check that the game isn't blocked by a VPN or firewall.