Extracted common code about error handling