Nil safety check to prevent crash due to a thrown exception.

The connection sometimes returns `nil`, which will throw an exception and crash the app if unchecked.