Add status code checking to request function
"Borrowed" from the servermod
This commit is contained in:
@@ -18,8 +18,9 @@ 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)
|
||||||
{
|
{
|
||||||
|
if(response.statusCode == 200 || response.statusCode == 201){
|
||||||
table DecodedJSON = DecodeJSON(response.body)
|
table DecodedJSON = DecodeJSON(response.body)
|
||||||
if ("map" in parameterTable)
|
if ("map" in parameterTable)
|
||||||
{
|
{
|
||||||
@@ -30,6 +31,10 @@ bool function pulseRequestData(string givenURL, table parameterTable, string tab
|
|||||||
pulseData[tablepath] <- DecodedJSON
|
pulseData[tablepath] <- DecodedJSON
|
||||||
}
|
}
|
||||||
pulseSuccessBool = false
|
pulseSuccessBool = false
|
||||||
|
} else {
|
||||||
|
pulseSuccessBool = true
|
||||||
|
pulsePrintt(format("%s %s is unreachable.", response.statusCode, givenURL))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure)
|
void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user