From 343f00798cec9cf74d3282f4fe75073215c10556 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 29 Mar 2024 14:23:29 +0100 Subject: [PATCH] fix: failded connection spam --- lua/gmod_integration/shared/sh_http.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index fd848b5..df2041a 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -1,10 +1,6 @@ local apiVersion = "v3" gmInte.http = gmInte.http || {} -// -// HTTP -// - local function getAPIURL(endpoint) local url = "https://" .. gmInte.config.apiFQDN .. "/" .. apiVersion @@ -22,7 +18,6 @@ local function getAPIURL(endpoint) end local function showableBody(endpoint) - // if start with /streams or /screenshots return false if (string.sub(endpoint, 1, 8) == "/streams" || string.sub(endpoint, 1, 12) == "/screenshots") then return false end @@ -34,6 +29,12 @@ local function genRequestID() return "gmInte-" .. util.CRC(tostring(SysTime())) end +local lastErrorMessages = 0 +local function noTokenError() + if (curTime() - lastErrorMessages < 10) then return end + gmInte.log("HTTP Failed: No token provided") +end + function gmInte.http.requestAPI(params) local body = params.body && util.TableToJSON(params.body || {}) || "" local bodyLength = string.len(body) @@ -46,6 +47,10 @@ function gmInte.http.requestAPI(params) local showableBody = showableBody(params.endpoint) local requestID = genRequestID() + if (token == "") then + return noTokenError() + end + local headers = { ["Content-Type"] = "application/json", ["Content-Length"] = bodyLength,