Skip to content

Commit

Permalink
Refactor update logger message when datafile fetching error (#74)
Browse files Browse the repository at this point in the history
* refactor: update error message and its details when datafile couldn't be fetched

* Fix swift format issue
  • Loading branch information
polok authored Jul 17, 2024
1 parent 8b5556e commit 554d96b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/FeaturevisorSDK/Instance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion Tests/FeaturevisorSDKTests/InstanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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() {
Expand Down

0 comments on commit 554d96b

Please sign in to comment.