How to reset data when encountered errors