So i have an api that i need to send a lot of request to it like 1 request for every 1.5 s
so the api after some time break and says too many request but it not giving me the respons it just give me error the api it self have a break time in the respons but
so how do i get the retry after tho it giving me an error ? Thanks
Use the retry_after parameter to respect the API limits so it stops dropping the requests:
local function makeRequest(...)
--do things here
--response is the API response in bytes
local data = game.HttpService:JSONDecode(response)
if data.message and data.message == "The resource is being rate limited." then
task.wait(data.retry_after)
return makeRequest(...) --redo the request after the time has passed
end
--continue processing the request as normal and return the expected data
end
Thereβs a chance the API normally wont return a JSON encoded dictionary(if the request is not rate limited), if thatβs the case try adding a pcall to your logic:
local success, data = pcall(function()
return game.HttpService:JSONDecode(response)
end)
if success and data.message and data.message == "The resource is being rate limited." then
task.wait(data.retry_after)
return makeRequest(...) --redo the request after the time has passed
end
--continue processing the request as normal and return the expected data
The error is JSON encoded, itβs not an actual coding error within your Roblox script. The pcall is checking if the API is returning a JSON or not without having to break/error your code. Depending on that it determines if youβre being rate limited or not(with a few more checks below).