Skip to content

Commit

Permalink
Actually handle errors from the SA API
Browse files Browse the repository at this point in the history
Doridian committed Mar 29, 2024
1 parent a1f70a5 commit 784d34d
Showing 3 changed files with 20 additions and 9 deletions.
16 changes: 8 additions & 8 deletions lua/sa/api/client/servers.lua
Original file line number Diff line number Diff line change
@@ -30,16 +30,20 @@ local function MkPlayerMap()
return res
end

function SA.API.RefreshServerList(cb)
local function SA_API_RefreshServerList()
local name = SA.API.GetServerName()
if (not name) or name == "" then
timer.Simple(0.1, function()
SA.API.RefreshServerList(cb)
SA_API_RefreshServerList()
end)
return
end

SA.API.ListServers(function(data)
SA.API.ListServers(function(data, code)
if code ~= 200 or not data then
return
end

serverList = {}

for k, srv in pairs(data) do
@@ -67,15 +71,11 @@ function SA.API.RefreshServerList(cb)
selfServer.ipport = game.GetIPAddress()
selfServer.online = true
end

if cb then
cb(data)
end
end)
end

local function SA_PeriodicServerListRefresh()
SA.API.RefreshServerList(function()
SA_API_RefreshServerList(function()
timer.Simple(60, SA_PeriodicServerListRefresh)
end)
end
5 changes: 4 additions & 1 deletion lua/sa/api/shared/main.lua
Original file line number Diff line number Diff line change
@@ -330,7 +330,10 @@ if SERVER then
end

local function SA_API_MakePlayerTokenCMD(ply)
SA_API_MakePlayerJWT(ply, function (data)
SA_API_MakePlayerJWT(ply, function (data, code)
if code ~= 200 or not data then
return
end
net.Start("SA_PlayerJWT")
net.WriteString(data.token)
net.WriteInt(data.expiry, 32)
8 changes: 8 additions & 0 deletions lua/sa/faction/client/application.lua
Original file line number Diff line number Diff line change
@@ -38,6 +38,10 @@ local function SA_RefreshApplications()
if code == 404 then
body = {}
end
if code ~= 200 then
print("Failed to list applications: " .. code)
return
end
SA.Application.Table = body
SA.Application.Refresh()
end)
@@ -46,6 +50,10 @@ local function SA_RefreshApplications()
if code == 404 then
body = {}
end
if code ~= 200 then
print("Failed to get application: " .. code)
return
end
SA.Application.Me = body
InitSelfApplication()
SA.Application.Refresh()

0 comments on commit 784d34d

Please sign in to comment.