From 4ff4d8f405d9db5d5a442f928ec401d0c5e9927f Mon Sep 17 00:00:00 2001 From: Marcin Polak Date: Tue, 16 Jul 2024 14:17:53 +0200 Subject: [PATCH 1/2] refactor: update error message and its details when datafile couldn't be fetched --- Sources/FeaturevisorSDK/Instance.swift | 2 +- Tests/FeaturevisorSDKTests/InstanceTests.swift | 5 ++++- 2 files changed, 5 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..6bcd6b0 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,7 @@ class FeaturevisorInstanceTests: XCTestCase { // THEN waitForExpectations(timeout: 1) XCTAssertTrue(wasDatafileContentFetchErrorThrown) + XCTAssertEqual(errorThrownDetails, "[\"error\": FeaturevisorSDK.FeaturevisorError.unparseableJSON(data: nil, errorMessage: \"Error :(\")]") } func testShouldGetVariable() { From 74d14e79ab37a2281e0fcefbced7000630c04c1a Mon Sep 17 00:00:00 2001 From: Marcin Polak Date: Tue, 16 Jul 2024 14:19:26 +0200 Subject: [PATCH 2/2] Fix swift format issue --- Tests/FeaturevisorSDKTests/InstanceTests.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tests/FeaturevisorSDKTests/InstanceTests.swift b/Tests/FeaturevisorSDKTests/InstanceTests.swift index 6bcd6b0..d28c1ca 100644 --- a/Tests/FeaturevisorSDKTests/InstanceTests.swift +++ b/Tests/FeaturevisorSDKTests/InstanceTests.swift @@ -1181,7 +1181,10 @@ class FeaturevisorInstanceTests: XCTestCase { // THEN waitForExpectations(timeout: 1) XCTAssertTrue(wasDatafileContentFetchErrorThrown) - XCTAssertEqual(errorThrownDetails, "[\"error\": FeaturevisorSDK.FeaturevisorError.unparseableJSON(data: nil, errorMessage: \"Error :(\")]") + XCTAssertEqual( + errorThrownDetails, + "[\"error\": FeaturevisorSDK.FeaturevisorError.unparseableJSON(data: nil, errorMessage: \"Error :(\")]" + ) } func testShouldGetVariable() {