From 554d96b86da8d22554f9a6d40ab99121aae9504a Mon Sep 17 00:00:00 2001 From: Marcin Polak Date: Wed, 17 Jul 2024 06:56:25 +0200 Subject: [PATCH] Refactor update logger message when datafile fetching error (#74) * refactor: update error message and its details when datafile couldn't be fetched * Fix swift format issue --- Sources/FeaturevisorSDK/Instance.swift | 2 +- Tests/FeaturevisorSDKTests/InstanceTests.swift | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/FeaturevisorSDK/Instance.swift b/Sources/FeaturevisorSDK/Instance.swift index 694ea41..2fe46a9 100644 --- a/Sources/FeaturevisorSDK/Instance.swift +++ b/Sources/FeaturevisorSDK/Instance.swift @@ -261,7 +261,7 @@ public class FeaturevisorInstance { self?.startRefreshing() } case .failure(let error): - self?.logger.error("Failed to fetch datafile: \(error)") + self?.logger.error("failed to fetch datafile", ["error": error]) } } } diff --git a/Tests/FeaturevisorSDKTests/InstanceTests.swift b/Tests/FeaturevisorSDKTests/InstanceTests.swift index 2c150ed..d28c1ca 100644 --- a/Tests/FeaturevisorSDKTests/InstanceTests.swift +++ b/Tests/FeaturevisorSDKTests/InstanceTests.swift @@ -1149,6 +1149,7 @@ class FeaturevisorInstanceTests: XCTestCase { // GIVEN let expectation = expectation(description: "datafile_error_response_expectation") var wasDatafileContentFetchErrorThrown = false + var errorThrownDetails: String? var options = InstanceOptions.default options.datafileUrl = "https://featurevisor.datafilecontent.com" options.handleDatafileFetch = { _ in @@ -1159,8 +1160,9 @@ class FeaturevisorInstanceTests: XCTestCase { return } - if message.contains("Failed to fetch datafile") { + if message.contains("failed to fetch datafile") { wasDatafileContentFetchErrorThrown = true + errorThrownDetails = details?.description } expectation.fulfill() @@ -1179,6 +1181,10 @@ class FeaturevisorInstanceTests: XCTestCase { // THEN waitForExpectations(timeout: 1) XCTAssertTrue(wasDatafileContentFetchErrorThrown) + XCTAssertEqual( + errorThrownDetails, + "[\"error\": FeaturevisorSDK.FeaturevisorError.unparseableJSON(data: nil, errorMessage: \"Error :(\")]" + ) } func testShouldGetVariable() {