Posted 22 July 2016 - 03:41 PM
Hello.
Me and a couple friends have been coding an entire system for our base, and we're trying to have a login system. If an incorrect password is put in, it goes to TimeAPI, fetches the time, and puts it into a log saying when it was, and what the ID of the system was.
Unfortunately, timeAPI sometimes goes down, and when it is, the system crashes, so then we have to restart the program.
Here is a (simplified) function we use for getting the real time:
The log writing file is later on, but this is the time getting function.
Is there someway we can write this so that if timeAPI is down, it doesn't crash at line 3, and maybe write a line to say 'TimeAPI was down'.
Cheers in advance.
Me and a couple friends have been coding an entire system for our base, and we're trying to have a login system. If an incorrect password is put in, it goes to TimeAPI, fetches the time, and puts it into a log saying when it was, and what the ID of the system was.
Unfortunately, timeAPI sometimes goes down, and when it is, the system crashes, so then we have to restart the program.
Here is a (simplified) function we use for getting the real time:
function getRealTime()
local realTimeURL = "http://www.timeapi.org/utc/now?format=%25a%20%25b%20%25d%20%25I:%25M:%25S%20%25Z%20%25Y"
local realTime = http.get(realTimeURL).readAll() --Crashes at this line when it's down
return realTime
end
The log writing file is later on, but this is the time getting function.
Is there someway we can write this so that if timeAPI is down, it doesn't crash at line 3, and maybe write a line to say 'TimeAPI was down'.
Cheers in advance.