Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pixel for sync unauthenticated response #376

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Sources/DDGSync/DDGSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class DDGSync: DDGSyncing {
public weak var dataProvidersSource: DataProvidersSource?

/// This is the constructor intended for use by app clients.
public convenience init(dataProvidersSource: DataProvidersSource, log: @escaping @autoclosure () -> OSLog = .disabled) {
let dependencies = ProductionDependencies(baseUrl: Constants.baseUrl, log: log())
public convenience init(dataProvidersSource: DataProvidersSource, errorEvents: EventMapping<SyncError>, log: @escaping @autoclosure () -> OSLog = .disabled) {
let dependencies = ProductionDependencies(baseUrl: Constants.baseUrl, errorEvents: errorEvents, log: log())
self.init(dataProvidersSource: dataProvidersSource, dependencies: dependencies)
}

Expand Down Expand Up @@ -255,8 +255,12 @@ public class DDGSync: DDGSyncing {

do {
try updateAccount(nil)
dependencies.errorEvents.fire(syncError)
} catch {
os_log(.error, log: dependencies.log, "Failed to delete account upon unauthenticated server response: %{public}s", error.localizedDescription)
if let syncError = error as? SyncError {
dependencies.errorEvents.fire(syncError)
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion Sources/DDGSync/internal/ProductionDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,33 @@ struct ProductionDependencies: SyncDependencies {
let secureStore: SecureStoring
let crypter: CryptingInternal
let scheduler: SchedulingInternal
let errorEvents: EventMapping<SyncError>

var log: OSLog {
getLog()
}
private let getLog: () -> OSLog

init(baseUrl: URL, log: @escaping @autoclosure () -> OSLog = .disabled) {
init(baseUrl: URL, errorEvents: EventMapping<SyncError>, log: @escaping @autoclosure () -> OSLog = .disabled) {

self.init(fileStorageUrl: FileManager.default.applicationSupportDirectoryForComponent(named: "Sync"),
baseUrl: baseUrl,
secureStore: SecureStorage(),
errorEvents: errorEvents,
log: log())
}

init(
fileStorageUrl: URL,
baseUrl: URL,
secureStore: SecureStoring,
errorEvents: EventMapping<SyncError>,
log: @escaping @autoclosure () -> OSLog = .disabled
) {
self.fileStorageUrl = fileStorageUrl
self.endpoints = Endpoints(baseUrl: baseUrl)
self.secureStore = secureStore
self.errorEvents = errorEvents
self.getLog = log

api = RemoteAPIRequestCreator(log: log())
Expand Down
1 change: 1 addition & 0 deletions Sources/DDGSync/internal/SyncDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protocol SyncDependencies {
var secureStore: SecureStoring { get }
var crypter: CryptingInternal { get }
var scheduler: SchedulingInternal { get }
var errorEvents: EventMapping<SyncError> { get }
var log: OSLog { get }

func createRemoteConnector(_ connectInfo: ConnectInfo) throws -> RemoteConnecting
Expand Down