Generalize error handling