Server Location HTTP 502

The code below errors with HTTP 502 (bad gateway) on line 3. Why is this (this script is to get the location of the server and display it to the players)

	local httpService = game:GetService("HttpService")
	**local serverInfo = httpService:JSONDecode(httpService:GetAsync("http://ip-api.com/json/"))**
	
	game.ReplicatedStorage.ServerLocation:FireClient(plr, "Server location: "..(serverInfo.city .. ", "..serverInfo.country))
end)```

I ran your code without issues both in studio as well as in a server.

Errors from 500 up mean something went wrong on the server side, and there’s not much we can do about it. Maybe there was an outage. 502 Bad gateway means the server that was acting as a proxy received an invalid response from the server it was trying to get info from (the upstream server).

Web requests may fail, hence pcalls are highly recommended, and possibly retry options.

local HttpService = game:GetService("HttpService")

local success, result do
	local retries = 0
	repeat
		retries += 1
		success, result = pcall(HttpService.GetAsync, HttpService, "http://ip-api.com/json/")
	until success or retries == 3
end

if success then
	local serverInfo = HttpService:JSONDecode(result)
	print(serverInfo.city, serverInfo.country)
else
	print("Error: "..result)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.