Improved error handling in loginAsync