Better error handling for authentication