Extracted common code for showing alerts.