Refactor gateway error reporting to be more extensible