handle connection errors properly