Refactor system error handling