refactor gateway error