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

update error messages #1999

Merged
merged 6 commits into from
Jan 2, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve readability of SyncErrorMessage assignments
  • Loading branch information
ayoy committed Jan 2, 2024
commit bbd1be51f42bfa98d11923a1620d17ed7880b62b
46 changes: 22 additions & 24 deletions DuckDuckGo/Preferences/Model/SyncPreferences.swift
Original file line number Diff line number Diff line change
@@ -211,8 +211,7 @@ final class SyncPreferences: ObservableObject, SyncUI.ManagementViewModel {
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.syncBookmarksPaused.rawValue)
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.syncCredentialsPaused.rawValue)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription)
}
}
}
@@ -361,8 +360,7 @@ extension SyncPreferences: ManagementDialogModelDelegate {
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.syncBookmarksPaused.rawValue)
UserDefaults.standard.set(false, forKey: UserDefaultsWrapper<Bool>.Key.syncCredentialsPaused.rawValue)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToDeleteData, description: error.localizedDescription)
}
}
}
@@ -375,8 +373,7 @@ extension SyncPreferences: ManagementDialogModelDelegate {
managementDialogModel.endFlow()
mapDevices(devices)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToUpdateDeviceName, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToUpdateDeviceName, description: error.localizedDescription)
}
}
}
@@ -416,8 +413,7 @@ extension SyncPreferences: ManagementDialogModelDelegate {
Pixel.fire(.syncSignupDirect)
presentDialog(for: .saveRecoveryCode(recoveryCode ?? ""))
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToSyncToServer, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToSyncToServer, description: error.localizedDescription)
}
}
}
@@ -443,11 +439,15 @@ extension SyncPreferences: ManagementDialogModelDelegate {
} catch {
if syncService.account == nil {
if isRecovery {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToSyncToServer, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(
type: .unableToSyncToServer,
description: error.localizedDescription
)
} else {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToSyncToOtherDevice, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(
type: .unableToSyncToOtherDevice,
description: error.localizedDescription
)
}
}
}
@@ -462,17 +462,15 @@ extension SyncPreferences: ManagementDialogModelDelegate {
func recoverDevice(recoveryCode: String, fromRecoveryScreen: Bool) {
Task { @MainActor in
guard let syncCode = try? SyncCode.decodeBase64String(recoveryCode) else {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .invalidCode, description: "")
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .invalidCode, description: "")
return
}
presentDialog(for: .prepareToSync)
if let recoveryKey = syncCode.recovery {
do {
try await loginAndShowPresentedDialog(recoveryKey, isRecovery: fromRecoveryScreen)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToMergeTwoAccounts, description: "")
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToMergeTwoAccounts, description: "")
}
} else if let connectKey = syncCode.connect {
do {
@@ -494,12 +492,13 @@ extension SyncPreferences: ManagementDialogModelDelegate {
}.store(in: &cancellables)
// The UI will update when the devices list changes.
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToSyncToOtherDevice, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(
type: .unableToSyncToOtherDevice,
description: error.localizedDescription
)
}
} else {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .invalidCode, description: "")
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .invalidCode, description: "")
return
}
}
@@ -530,8 +529,7 @@ extension SyncPreferences: ManagementDialogModelDelegate {
do {
try data.writeFileWithProgress(to: location)
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableCreateRecoveryPDF, description: error.localizedDescription)
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableCreateRecoveryPDF, description: error.localizedDescription)
}
}

@@ -545,8 +543,8 @@ extension SyncPreferences: ManagementDialogModelDelegate {
refreshDevices()
managementDialogModel.endFlow()
} catch {
managementDialogModel.syncErrorMessage
= SyncErrorMessage(type: .unableToRemoveDevice, description: error.localizedDescription) }
managementDialogModel.syncErrorMessage = SyncErrorMessage(type: .unableToRemoveDevice, description: error.localizedDescription)
}
}
}