Improve error handling of login