Skip to content

Commit 74fb385

Browse files
authored
DX-2227: Added better error logging (#23)
1 parent fca214b commit 74fb385

File tree

1 file changed

+38
-61
lines changed

1 file changed

+38
-61
lines changed

Source/Immutable/Private/Immutable/ImmutablePassport.cpp

Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ FString FImmutablePassportZkEvmGetBalanceData::ToJsonString() const
132132
FString FImtblTransactionRequest::ToJsonString() const
133133
{
134134
FString OutString;
135-
135+
136136
FJsonObjectWrapper Wrapper;
137137
Wrapper.JsonObject = MakeShared<FJsonObject>();
138138
FJsonObjectConverter::UStructToJsonObject(FImtblTransactionRequest::StaticStruct(), this, Wrapper.JsonObject.ToSharedRef(), 0, 0);
139-
139+
140140
if (!Wrapper.JsonObject.IsValid())
141141
{
142142
IMTBL_ERR("Could not convert FImtblTransactionRequest to JSON")
@@ -150,10 +150,10 @@ FString FImtblTransactionRequest::ToJsonString() const
150150
CustomDataArray.Add(MakeShared<FJsonValueObject>(FJsonValueObject(CustomData.ToJsonObject())));
151151
}
152152
Wrapper.JsonObject->SetArrayField("customData", CustomDataArray);
153-
153+
154154
Wrapper.JsonObjectToString(OutString);
155155

156-
156+
157157
return OutString;
158158
}
159159

@@ -244,7 +244,7 @@ void UImmutablePassport::ZkEvmGetBalance(const FImmutablePassportZkEvmGetBalance
244244
}
245245

246246
void UImmutablePassport::ZkEvmSendTransaction(const FImtblTransactionRequest& Request, const FImtblPassportResponseDelegate& ResponseDelegate)
247-
{
247+
{
248248
CallJS(
249249
ImmutablePassportAction::ZkEvmSendTransaction,
250250
Request.ToJsonString(),
@@ -382,11 +382,8 @@ void UImmutablePassport::OnInitializeResponse(FImtblJSResponse Response)
382382
}
383383
else
384384
{
385-
IMTBL_LOG("Passport initialization failed.")
386-
if (Response.Error.IsSet())
387-
{
388-
Msg = Response.Error->ToString();
389-
}
385+
IMTBL_ERR("Passport initialization failed.")
386+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
390387
}
391388

392389
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{Response.success, Msg, Response});
@@ -405,8 +402,7 @@ void UImmutablePassport::OnCheckStoredCredentialsResponse(FImtblJSResponse Respo
405402
{
406403
IMTBL_LOG("No stored credentials found.");
407404
FString Msg;
408-
if (Response.Error.IsSet())
409-
Msg = Response.Error->ToString();
405+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
410406
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{false, Msg, Response});
411407
}
412408
else
@@ -429,8 +425,7 @@ void UImmutablePassport::OnConnectSilentResponse(FImtblJSResponse Response)
429425
{
430426
IMTBL_LOG("No stored credentials found.");
431427
FString Msg;
432-
if (Response.Error.IsSet())
433-
Msg = Response.Error->ToString();
428+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
434429
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{false, Msg, Response});
435430
return;
436431
}
@@ -460,8 +455,7 @@ void UImmutablePassport::OnConnectWithCredentialsResponse(FImtblJSResponse Respo
460455
else
461456
{
462457
IMTBL_LOG("Connect with credentials failed.");
463-
if (Response.Error.IsSet())
464-
Msg = Response.Error->ToString();
458+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
465459
// Send log out action to Passport and move on, logging and ignoring the response
466460
JSConnector->CallJS(ImmutablePassportAction::Logout, TEXT(""), FImtblJSResponseDelegate::CreateUObject(this, &UImmutablePassport::LogAndIgnoreResponse));
467461
}
@@ -482,9 +476,8 @@ void UImmutablePassport::OnLogoutResponse(FImtblJSResponse Response)
482476
}
483477
else
484478
{
485-
IMTBL_LOG("Error logging out.")
486-
if (Response.Error.IsSet())
487-
Msg = Response.Error->ToString();
479+
IMTBL_ERR("Error logging out.")
480+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
488481
}
489482
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{Response.success, Msg, Response});
490483
}
@@ -499,11 +492,8 @@ void UImmutablePassport::OnConnectResponse(FImtblJSResponse Response)
499492
if (!Response.success || !ConnectData || !ConnectData->code.Len())
500493
{
501494
FString Msg;
502-
IMTBL_LOG("Connect attempt failed.");
503-
if (Response.Error.IsSet())
504-
{
505-
Msg = Response.Error->ToString();
506-
}
495+
IMTBL_WARN("Connect attempt failed.");
496+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
507497
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{false, Msg, Response});
508498
return;
509499
}
@@ -531,9 +521,8 @@ void UImmutablePassport::OnConnectEvmResponse(FImtblJSResponse Response)
531521
}
532522
else
533523
{
534-
IMTBL_LOG("Error connecting to Evm.")
535-
if (Response.Error.IsSet())
536-
Msg = Response.Error->ToString();
524+
IMTBL_WARN("Error connecting to Evm.")
525+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
537526
}
538527
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{Response.success, Msg});
539528
}
@@ -601,9 +590,8 @@ void UImmutablePassport::OnConnectPKCEResponse(FImtblJSResponse Response)
601590
}
602591
else
603592
{
604-
IMTBL_LOG("Connect PKCE attempt failed.");
605-
if (Response.Error.IsSet())
606-
Msg = Response.Error->ToString();
593+
IMTBL_WARN("Connect PKCE attempt failed.");
594+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
607595
}
608596
PKCEResponseDelegate.ExecuteIfBound(FImmutablePassportResult{Response.success, Msg});
609597
PKCEResponseDelegate = nullptr;
@@ -626,9 +614,8 @@ void UImmutablePassport::OnGetAddressResponse(FImtblJSResponse Response)
626614
bool bSuccess = true;
627615
if (!Response.success || !Response.JsonObject->HasTypedField<EJson::String>(TEXT("result")))
628616
{
629-
IMTBL_LOG("Could not fetch address from Passport.");
630-
if (Response.Error.IsSet())
631-
Msg = Response.Error->ToString();
617+
IMTBL_WARN("Could not fetch address from Passport.");
618+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
632619
bSuccess = false;
633620
}
634621
else
@@ -649,9 +636,8 @@ void UImmutablePassport::OnZkEvmRequestAccountsResponse(FImtblJSResponse Respons
649636
bool bSuccess = true;
650637
if (!Response.success || !Response.JsonObject->HasTypedField<EJson::Array>(TEXT("accounts")))
651638
{
652-
IMTBL_LOG("Error requesting zkevm accounts.")
653-
if (Response.Error.IsSet())
654-
Msg = Response.Error->ToString();
639+
IMTBL_WARN("Error requesting zkevm accounts.")
640+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
655641
bSuccess = false;
656642
}
657643
else
@@ -679,9 +665,8 @@ void UImmutablePassport::OnZkEvmGetBalanceResponse(FImtblJSResponse Response)
679665
bool bSuccess = true;
680666
if (!Response.success || !Response.JsonObject->HasTypedField<EJson::String>(TEXT("result")))
681667
{
682-
IMTBL_LOG("Could not get balance.");
683-
if (Response.Error.IsSet())
684-
Msg = Response.Error->ToString();
668+
IMTBL_WARN("Could not get balance.");
669+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
685670
bSuccess = false;
686671
}
687672
else
@@ -700,9 +685,8 @@ void UImmutablePassport::OnZkEvmSendTransactionResponse(FImtblJSResponse Respons
700685
bool bSuccess = true;
701686
if (!Response.success || !Response.JsonObject->HasTypedField<EJson::String>(TEXT("result")))
702687
{
703-
IMTBL_LOG("Could not fetch send transaction.");
704-
if (Response.Error.IsSet())
705-
Msg = Response.Error->ToString();
688+
IMTBL_WARN("Could not fetch send transaction.");
689+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
706690
bSuccess = false;
707691
}
708692
else
@@ -725,9 +709,8 @@ void UImmutablePassport::OnConfirmCodeResponse(FImtblJSResponse Response)
725709
}
726710
else
727711
{
728-
IMTBL_LOG("Login code not confirmed.")
729-
if (Response.Error.IsSet())
730-
Msg = Response.Error->ToString();
712+
IMTBL_WARN("Login code not confirmed.")
713+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
731714
}
732715
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{Response.success, Msg, Response});
733716
}
@@ -744,9 +727,8 @@ void UImmutablePassport::OnGetEmailResponse(FImtblJSResponse Response)
744727
bool bSuccess = true;
745728
if (!Response.success || !Response.JsonObject->HasTypedField<EJson::String>(TEXT("result")))
746729
{
747-
IMTBL_LOG("Connect attempt failed.");
748-
if (Response.Error.IsSet())
749-
Msg = Response.Error->ToString();
730+
IMTBL_WARN("Connect attempt failed.");
731+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
750732
bSuccess = false;
751733
}
752734
else
@@ -767,17 +749,13 @@ void UImmutablePassport::OnTransferResponse(FImtblJSResponse Response)
767749
bool bSuccess = true;
768750
if (!Response.success)
769751
{
770-
IMTBL_LOG("ImxTransfer failed.");
771-
if (Response.Error.IsSet())
772-
{
773-
Msg = Response.Error->ToString();
774-
}
775-
752+
IMTBL_WARN("ImxTransfer failed.");
753+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
776754
bSuccess = false;
777755
}
778756
else
779757
{
780-
Msg = Response.JsonObject->GetStringField(TEXT("result"));
758+
Msg = Response.JsonObject->GetStringField(TEXT("status"));
781759
}
782760
ResponseDelegate->ExecuteIfBound(FImmutablePassportResult{bSuccess, Msg, Response});
783761
}
@@ -793,11 +771,8 @@ void UImmutablePassport::OnBatchNftTransferResponse(FImtblJSResponse Response)
793771
bool bSuccess = true;
794772
if (!Response.success || !Response.JsonObject->HasTypedField<EJson::Object>(TEXT("result")))
795773
{
796-
IMTBL_LOG("ImxBatchNftTransfer failed.");
797-
if (Response.Error.IsSet())
798-
{
799-
Msg = Response.Error->ToString();
800-
}
774+
IMTBL_WARN("ImxBatchNftTransfer failed.");
775+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
801776
bSuccess = false;
802777
}
803778
else
@@ -817,7 +792,9 @@ void UImmutablePassport::LogAndIgnoreResponse(FImtblJSResponse Response)
817792
}
818793
else
819794
{
820-
IMTBL_WARN("Received error response from Passport for action %s -- %s", *Response.responseFor, *Response.Error->ToString());
795+
FString Msg;
796+
Response.Error.IsSet() ? Msg = Response.Error->ToString() : Msg = Response.JsonObject->GetStringField(TEXT("error"));
797+
IMTBL_WARN("Received error response from Passport for action %s -- %s", *Response.responseFor, *Msg);
821798
}
822799
}
823800

0 commit comments

Comments
 (0)