refactor - reuser error code handling