Added try-catch block to log correctly connection errors