Refactor: extract function logError()