Refactor error handlers for authentication