Fix NullPointerException caused by connection error