From 0d15e155ff38aabcbbbaa2e1e7dd084268eb5f64 Mon Sep 17 00:00:00 2001 From: Oprea Alexandru Date: Sat, 31 Aug 2024 09:48:51 +0300 Subject: [PATCH] refactor error printing --- .../ConfigCat/Private/ConfigCatSubsystem.cpp | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Source/ConfigCat/Private/ConfigCatSubsystem.cpp b/Source/ConfigCat/Private/ConfigCatSubsystem.cpp index 27d0086..d73f313 100644 --- a/Source/ConfigCat/Private/ConfigCatSubsystem.cpp +++ b/Source/ConfigCat/Private/ConfigCatSubsystem.cpp @@ -27,6 +27,15 @@ using namespace configcat; namespace { + void PrintError(const FString& ErrorMessage) + { + if (GEngine) + { + GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("[ConfigCat] %s"), *ErrorMessage)); + } + UE_LOG(LogConfigCat, Error, TEXT("%s"), *ErrorMessage); + } + bool EnsureConfigCatClient(const std::shared_ptr& Client) { if (Client) @@ -34,12 +43,7 @@ namespace return true; } - UE_LOG(LogConfigCat, Error, TEXT("Trying to access the ConfigCatClient before initialization or after shutdown.")); - if(GEngine) - { - GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("Trying to access the ConfigCatClient before initialization or after shutdown.")); - } - + PrintError(TEXT("Trying to access the client before initialization or after shutdown.")); return false; } @@ -284,12 +288,7 @@ void UConfigCatSubsystem::Initialize(FSubsystemCollectionBase& Collection) const UConfigCatSettings* ConfigCatSettings = GetDefault(); if (!ConfigCatSettings || ConfigCatSettings->SdkKey.IsEmpty()) { - if(GEngine) - { - GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("ConfigCat SdkKey missing. Please set your SdkKey in the Project Settings.")); - } - - UE_LOG(LogConfigCat, Error, TEXT("ConfigCat SdkKey missing. Please set your SdkKey in the Project Settings.")); + PrintError(TEXT("SdkKey missing. Please set your SdkKey in the Project Settings.")); return; }