Add status code checking to request function
"Borrowed" from the servermod
This commit is contained in:
@@ -18,18 +18,23 @@ void function pulsePrintt(string content) //Prints whatever we want printed with
|
|||||||
bool function pulseRequestData(string givenURL, table parameterTable, string tablepath) //Gets data from API (see ToneURL within mod.json) and puts it into one table for processing.
|
bool function pulseRequestData(string givenURL, table parameterTable, string tablepath) //Gets data from API (see ToneURL within mod.json) and puts it into one table for processing.
|
||||||
{
|
{
|
||||||
table<string, array<string> > requestTable
|
table<string, array<string> > requestTable
|
||||||
void functionref (HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) : (parameterTable, requestTable, tablepath)
|
void functionref (HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) : (givenURL, parameterTable, requestTable, tablepath)
|
||||||
{
|
{
|
||||||
table DecodedJSON = DecodeJSON(response.body)
|
if(response.statusCode == 200 || response.statusCode == 201){
|
||||||
if ("map" in parameterTable)
|
table DecodedJSON = DecodeJSON(response.body)
|
||||||
{
|
if ("map" in parameterTable)
|
||||||
string mapName = expect string(parameterTable["map"])
|
{
|
||||||
withMapName[mapName] <- DecodedJSON
|
string mapName = expect string(parameterTable["map"])
|
||||||
pulseData[tablepath] <- withMapName
|
withMapName[mapName] <- DecodedJSON
|
||||||
|
pulseData[tablepath] <- withMapName
|
||||||
|
} else {
|
||||||
|
pulseData[tablepath] <- DecodedJSON
|
||||||
|
}
|
||||||
|
pulseSuccessBool = false
|
||||||
} else {
|
} else {
|
||||||
pulseData[tablepath] <- DecodedJSON
|
pulseSuccessBool = true
|
||||||
|
pulsePrintt(format("%s %s is unreachable.", response.statusCode, givenURL))
|
||||||
}
|
}
|
||||||
pulseSuccessBool = false
|
|
||||||
}
|
}
|
||||||
void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure)
|
void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user