consolidate some duplicate error handling