Skip to content

Commit

Permalink
fix: dns error callback
Browse files Browse the repository at this point in the history
Fixes: #815
  • Loading branch information
Ryan Phillips committed Oct 18, 2015
1 parent 22f11b0 commit a9ebf36
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions deps/dns.lua
Expand Up @@ -300,8 +300,9 @@ local function parse_response(buf, id)
local answers = {}

if code ~= 0 then
answers.errcode = code
answers.errstr = resolver_errstrs[code] or "unknown"
answers = Error:new(
code .. ': ' .. resolver_errstrs[code] or "unknown"
)
end

for i = 1, nan do
Expand Down Expand Up @@ -624,7 +625,11 @@ local function _query(servers, name, dnsclass, qtype, callback)
if not answers then
timer.setImmediate(tcp_iter)
else
callback(nil, answers)
if answers.code then
callback(answers)
else
callback(nil, answers)
end
end
end

Expand Down Expand Up @@ -659,7 +664,11 @@ local function _query(servers, name, dnsclass, qtype, callback)
sock:close()
local answers, err = parse_response(msg, id)
if answers then
callback(nil, answers)
if answers.code then
callback(answers)
else
callback(nil, answers)
end
else
if err == 'truncated' then
timer.setImmediate(tcp_iter)
Expand Down

0 comments on commit a9ebf36

Please sign in to comment.