void UPlayFabMatchmakerAPI::OnProcessRequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) { // Be sure that we have no data from previous response ResetResponseData(); FPlayFabBaseModel myResponse; // Check we have result to process futher if (!bWasSuccessful) { UE_LOG(LogPlayFab, Error, TEXT("Request failed: %s"), *Request->GetURL()); // Broadcast the result event myResponse.responseError.ErrorCode = 500; myResponse.responseError.ErrorName = "Request Error"; myResponse.responseError.ErrorMessage = "HTTP Request Error"; myResponse.responseData = ResponseJsonObj; Matchmaker_proxy->OnPlayFabResponse.Broadcast(myResponse, false); return; } // Save response data as a string ResponseContent = Response->GetContentAsString(); // Save response code as int32 ResponseCode = Response->GetResponseCode(); // Try to deserialize data to JSON TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(ResponseContent); FJsonSerializer::Deserialize(JsonReader, ResponseJsonObj->GetRootObject()); // Decide whether the request was successful bIsValidJsonResponse = bWasSuccessful && ResponseJsonObj->GetRootObject().IsValid(); // Log errors if (!bIsValidJsonResponse) { if (!ResponseJsonObj->GetRootObject().IsValid()) { // As we assume it's recommended way to use current class, but not the only one, // it will be the warning instead of error UE_LOG(LogPlayFab, Warning, TEXT("JSON could not be decoded!")); } } // Serialize data to json string FString InputString; TSharedRef< TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&InputString); FJsonSerializer::Serialize(ResponseJsonObj->GetRootObject().ToSharedRef(), Writer); // Log response state UE_LOG(LogPlayFab, Log, TEXT("Response : %s"), *InputString); myResponse.responseError.decodeError(ResponseJsonObj); myResponse.responseData = ResponseJsonObj; // Broadcast the result event Matchmaker_proxy->OnPlayFabResponse.Broadcast(myResponse, true); }
void USIOJRequestJSON::OnProcessRequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) { // Be sure that we have no data from previous response ResetResponseData(); // Check we have a response and save response code as int32 if(Response.IsValid()) { ResponseCode = Response->GetResponseCode(); } // Check we have result to process futher if (!bWasSuccessful || !Response.IsValid()) { UE_LOG(LogSIOJ, Error, TEXT("Request failed (%d): %s"), ResponseCode, *Request->GetURL()); // Broadcast the result event OnRequestFail.Broadcast(this); OnStaticRequestFail.Broadcast(this); return; } // Save response data as a string ResponseContent = Response->GetContentAsString(); // Log response state UE_LOG(LogSIOJ, Log, TEXT("Response (%d): %s"), ResponseCode, *ResponseContent); // Process response headers TArray<FString> Headers = Response->GetAllHeaders(); for (FString Header : Headers) { FString Key; FString Value; if (Header.Split(TEXT(": "), &Key, &Value)) { ResponseHeaders.Add(Key, Value); } } // Try to deserialize data to JSON TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(ResponseContent); FJsonSerializer::Deserialize(JsonReader, ResponseJsonObj->GetRootObject()); // Decide whether the request was successful bIsValidJsonResponse = bWasSuccessful && ResponseJsonObj->GetRootObject().IsValid(); // Log errors if (!bIsValidJsonResponse) { if (!ResponseJsonObj->GetRootObject().IsValid()) { // As we assume it's recommended way to use current class, but not the only one, // it will be the warning instead of error UE_LOG(LogSIOJ, Warning, TEXT("JSON could not be decoded!")); } } // Broadcast the result event OnRequestComplete.Broadcast(this); OnStaticRequestComplete.Broadcast(this); // Finish the latent action if (ContinueAction) { FSIOJLatentAction<USIOJsonObject*> *K = ContinueAction; ContinueAction = nullptr; K->Call(ResponseJsonObj); } }
void USIOJRequestJSON::ResetData() { ResetRequestData(); ResetResponseData(); }
void USIOJRequestJSON::Cancel() { ContinueAction = nullptr; ResetResponseData(); }