better error handling during authentication