diff --git a/gateway/src/resty/http_ng/backend/resty.lua b/gateway/src/resty/http_ng/backend/resty.lua index 0dfb748ef..0cc7a3b71 100644 --- a/gateway/src/resty/http_ng/backend/resty.lua +++ b/gateway/src/resty/http_ng/backend/resty.lua @@ -37,7 +37,7 @@ backend.send = function(_, request) local httpc, err = http_proxy.new(request) if err then - return nil, err + return response.error(request, err) end if httpc then diff --git a/spec/resty/http_ng/backend/resty_spec.lua b/spec/resty/http_ng/backend/resty_spec.lua index 9f4e5ff7c..dba755bfe 100755 --- a/spec/resty/http_ng/backend/resty_spec.lua +++ b/spec/resty/http_ng/backend/resty_spec.lua @@ -37,8 +37,11 @@ describe('resty backend', function() local req = { method = method, url = 'http://0.0.0.0:0/' } local response, err = backend:send(req) - assert.falsy(response) - assert.equal("connection refused", err) + assert.falsy(err) + assert.truthy(response.error) + assert.equal("connection refused", response.error) + assert.falsy(response.ok) + assert.same(req, response.request) end) context('http proxy is set', function() diff --git a/spec/resty/http_ng_spec.lua b/spec/resty/http_ng_spec.lua index 1fdcb8b85..b14eafa0b 100755 --- a/spec/resty/http_ng_spec.lua +++ b/spec/resty/http_ng_spec.lua @@ -224,18 +224,18 @@ describe('http_ng', function() end) describe('when there is error #network', function() - local response, err + local response before_each(function() http = http_ng.new{ backend = resty_backend } - response, err = http.get('http://127.0.0.1:1') + response = http.get('http://127.0.0.1:1') end) it('is not ok', function() - assert.falsy(response) + assert.equal(false, response.ok) end) it('has error', function() - assert.equal("connection refused", err) + assert.equal("connection refused", response.error) end) end)