refactored authentication error handling