Skip to content

Commit 21a2f49

Browse files
committed
[http_ng] Fix regression
In PR #1503 we return nil and error in case of an error, however some code paths do not handle the error but instead check the error field of the response object and lead to unexpected behavior. With this PR, we will return a response object with the error field set.
1 parent 481b1b3 commit 21a2f49

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

gateway/src/resty/http_ng/backend/resty.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ backend.send = function(_, request)
3737
local httpc, err = http_proxy.new(request)
3838

3939
if err then
40-
return nil, err
40+
return response.error(request, err)
4141
end
4242

4343
if httpc then

spec/resty/http_ng/backend/resty_spec.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ describe('resty backend', function()
3737
local req = { method = method, url = 'http://0.0.0.0:0/' }
3838
local response, err = backend:send(req)
3939

40-
assert.falsy(response)
41-
assert.equal("connection refused", err)
40+
assert.falsy(err)
41+
assert.truthy(response.error)
42+
assert.equal("connection refused", response.error)
43+
assert.falsy(response.ok)
44+
assert.same(req, response.request)
4245
end)
4346

4447
context('http proxy is set', function()

spec/resty/http_ng_spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,18 @@ describe('http_ng', function()
224224
end)
225225

226226
describe('when there is error #network', function()
227-
local response, err
227+
local response
228228
before_each(function()
229229
http = http_ng.new{ backend = resty_backend }
230-
response, err = http.get('http://127.0.0.1:1')
230+
response = http.get('http://127.0.0.1:1')
231231
end)
232232

233233
it('is not ok', function()
234-
assert.falsy(response)
234+
assert.equal(false, response.ok)
235235
end)
236236

237237
it('has error', function()
238-
assert.equal("connection refused", err)
238+
assert.equal("connection refused", response.error)
239239
end)
240240
end)
241241

0 commit comments

Comments
 (0)