I have created a UObject to perform GET and POST requests (UNetworkObject). I’m trying to set a timer on network failure to re-attempt a connection after x seconds.
HTTPOnRequestFailed is called when there has been an error with a request:
void UNetworkObject::HTTPOnRequestFailed() {
//request failed and we need to continue re-trying connection.
if(this->CurrentNumRetries < this->NumRetries)
{
TObjectIterator<UWorld> Itr;
if(Itr){
UWorld* World = Itr->GetWorld();
if (World) {
if (this->CurrentMethod.Equals("GET", ESearchCase::IgnoreCase)) {
UE_LOG(LogTemp, Warning, TEXT("Re-attempting failed GET request"));
World->GetTimerManager().SetTimer(RetryTimerHandle, this, &UNetworkObject::HttpGetRetry, this->TimeBetweenRetries, false, this->TimeBetweenRetries);
return;
}
else if (this->CurrentMethod.Equals("POST", ESearchCase::IgnoreCase)) {
UE_LOG(LogTemp, Warning, TEXT("Re-attempting failed POST request"));
World->GetTimerManager().SetTimer(RetryTimerHandle, this, &UNetworkObject::HttpPostRetry, this->TimeBetweenRetries, false, this->TimeBetweenRetries);
return;
}
}
}
}
this->isBusy = false;
RequestData_OnReceived.Broadcast(REQUEST_ERROR_RESPONSE);
}
HttpPostRetry is supposed to be called by the timer after (float)TimeBetweenRetries seconds. HttpGetRetry is nearly identical and also never gets called.
void UNetworkObject::HttpPostRetry() {
UE_LOG(LogTemp, Warning, TEXT("Post retry called"));
HttpPost(this->CurrentHost, this->CurrentJsonData, true);
}
I see “Re-attempting failed POST request” but “Post retry called” never shows up in the log so HttpPostRetry() is never being called by the timer.