Factorize the failure of connecting and logging in

And do not cache on failing to connect. It is possible that a server was
down and it will be up later.
Add .gitignore