Added logging and improved error catching when using basic authentication