Fixed error handling on authentication