How can I show an error message based on a condition?