properly handle gateway error responses