Skip to content

Commit bb86a49

Browse files
committed
Fix errors when returning tables from subscripts
1 parent c82fad0 commit bb86a49

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/Classes/PoEAPI.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ function PoEAPIClass:FetchAuthToken(callback)
8080
if id then
8181
launch.subScripts[id] = {
8282
type = "DOWNLOAD",
83-
callback = function(response, errMsg)
84-
local code, state, port = unpack(response or {})
83+
callback = function(code, errMsg, state, port)
8584
if not code then
8685
ConPrintf("Failed to get code from server: %s", errMsg)
8786
self.authToken = nil

src/Launch.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,14 @@ function launch:DownloadPage(url, callback, params)
299299
errMsg = "No data returned"
300300
end
301301
ConPrintf("Download complete. Status: %s", errMsg or "OK")
302-
return {responseHeader, responseBody}, errMsg
302+
return responseBody, errMsg, responseHeader
303303
]]
304304
local id = LaunchSubScript(script, "", "ConPrintf", url, params.header, params.body, self.connectionProtocol, self.proxyURL)
305305
if id then
306306
self.subScripts[id] = {
307307
type = "DOWNLOAD",
308-
callback = function(response, errMsg)
309-
if response then
310-
callback({header=response[1], body=response[2]}, errMsg)
311-
else
312-
callback({}, errMsg)
313-
end
308+
callback = function(responseBody, errMsg, responseHeader)
309+
callback({header=responseHeader, body=responseBody}, errMsg)
314310
end
315311
}
316312
end

src/LaunchServer.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ end
177177
-- IO, so that it can operate concurrently, but hopefully that isn't necessary.
178178
local attempt = 1
179179
local stopAt = os.time() + 30
180+
local errMsg
180181
local shouldRetry, code, state = true, nil, nil
181182
while (os.time() < stopAt) and shouldRetry do
182183
-- `settimeout`` applies only to individual operations, but we're more concerned with not spending more than 30
@@ -197,4 +198,7 @@ while (os.time() < stopAt) and shouldRetry do
197198
attempt = attempt + 1
198199
end
199200
server:close()
200-
return {code, state, port}
201+
if os.time() >= stopAt then
202+
errMsg = "Timeout reached without a response received by the local server"
203+
end
204+
return code, errMsg, state, port

0 commit comments

Comments
 (0)