From de0588d02cf552a2f7aa40c9d00db6c72af6f297 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 23:55:57 +0100 Subject: [PATCH] add: requestID --- lua/gmod_integration/shared/sh_http.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index 5f7aaf8..94855de 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -33,6 +33,10 @@ local function showableBody(endpoint) return true end +local function genRequestID() + return "gmInte-" .. util.CRC(tostring(SysTime())) +end + function gmInte.http.requestAPI(params) local body = params.body && util.TableToJSON(params.body || {}) || "" local bodyLength = string.len(body) @@ -43,6 +47,7 @@ function gmInte.http.requestAPI(params) local failed = params.failed || function() if (!gmInte.config.debug) then gmInte.log("HTTP Failed, if this error persists please contact support") end end local version = gmInte.config.version local showableBody = showableBody(params.endpoint) + local requestID = genRequestID() local headers = { ["Content-Type"] = "application/json", @@ -54,6 +59,7 @@ function gmInte.http.requestAPI(params) // Log if (gmInte.config.devInstance) then gmInte.log("HTTP Using dev Instance", true) end + gmInte.log("HTTP Request ID: " .. requestID, true) gmInte.log("HTTP Request: " .. method .. " " .. url, true) gmInte.log("HTTP Body: " .. (showableBody && body || "HIDDEN"), true) @@ -66,6 +72,7 @@ function gmInte.http.requestAPI(params) ["type"] = type, ["success"] = function(code, body, headers) // Log + gmInte.log("HTTP Request ID: " .. requestID, true) gmInte.log("HTTP Response: " .. code, true) if (gmInte.config.debug) then gmInte.log("HTTP Body: " .. body, true) end @@ -88,6 +95,7 @@ function gmInte.http.requestAPI(params) end, ["failed"] = function(error) // Log + gmInte.log("HTTP Request ID: " .. requestID, true) gmInte.log("HTTP Failed: " .. error, true) // Return failed