Skip to content

Commit

Permalink
added log wrappers and included it in Indexer requests
Browse files Browse the repository at this point in the history
  • Loading branch information
andygruening committed Sep 20, 2024
1 parent 5ec448f commit 043735c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Http.h"
#include "Util/SequenceSupport.h"
#include "HttpManager.h"
#include "Util/Log.h"

UIndexer::UIndexer(){}

Expand Down Expand Up @@ -40,27 +41,34 @@ FString UIndexer::HostName(const int64 ChainID)
*/
void UIndexer::HTTPPost(const int64& ChainID,const FString& Endpoint,const FString& Args, const TSuccessCallback<FString>& OnSuccess, const FFailureCallback& OnFailure) const
{
UE_LOG(LogTemp, Display, TEXT("Url: %s"), *this->Url(ChainID,Endpoint));
const FString Url = *this->Url(ChainID,Endpoint);
const TSharedRef<IHttpRequest> HTTP_Post_Req = FHttpModule::Get().CreateRequest();

SEQ_LOG_EDITOR(Display, TEXT("POST >> %s with payload %s"), *Url, *Args);

HTTP_Post_Req->SetVerb("POST");
HTTP_Post_Req->SetHeader("Content-Type", "application/json");//2 differing headers for the request
HTTP_Post_Req->SetHeader("Accept", "application/json");
HTTP_Post_Req->SetTimeout(30);
HTTP_Post_Req->SetURL(this->Url(ChainID, Endpoint));
HTTP_Post_Req->SetURL(Url);
HTTP_Post_Req->SetContentAsString(Args);
HTTP_Post_Req->OnProcessRequestComplete().BindLambda([OnSuccess, OnFailure](const FHttpRequestPtr& Request, FHttpResponsePtr Response, const bool bWasSuccessful)
{
if(bWasSuccessful)
{
const FString Content = Request->GetResponse()->GetContentAsString();
SEQ_LOG_EDITOR(Display, TEXT("POST << %d %s (from %s)"), Request->GetResponse()->GetResponseCode(), *Content, *Request->GetURL());

OnSuccess(Content);
}
else
{
if(Request.IsValid() && Request->GetResponse().IsValid())
{
OnFailure(FSequenceError(RequestFail, "Request failed: " + Request->GetResponse()->GetContentAsString()));
const FString Content = Request->GetResponse()->GetContentAsString();
SEQ_LOG_EDITOR(Error, TEXT("POST << %d %s (from %s)"), Request->GetResponse()->GetResponseCode(), *Content, *Request->GetURL());

OnFailure(FSequenceError(RequestFail, "Request failed: " + Content));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2024 Horizon Blockchain Games Inc. All rights reserved.

#include "Log.h"

DEFINE_LOG_CATEGORY(LogSequence);
DEFINE_LOG_CATEGORY(LogSequenceEditor);
13 changes: 13 additions & 0 deletions Plugins/SequencePlugin/Source/SequencePlugin/Private/Util/Log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2024 Horizon Blockchain Games Inc. All rights reserved.
#pragma once

DECLARE_LOG_CATEGORY_EXTERN(LogSequence, Log, All);
DECLARE_LOG_CATEGORY_EXTERN(LogSequenceEditor, Log, All);

#define SEQ_LOG(Verbosity, Format, ...) UE_LOG(LogSequence, Verbosity, Format, ##__VA_ARGS__)

#if WITH_EDITOR
#define SEQ_LOG_EDITOR(Verbosity, Format, ...) UE_LOG(LogSequenceEditor, Verbosity, Format, ##__VA_ARGS__)
#else
#define SEQ_LOG_EDITOR(Verbosity, Format, ...) do {} while (0)
#endif

0 comments on commit 043735c

Please sign in to comment.