Skip to content

Commit

Permalink
Add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jan 10, 2025
1 parent 5879f6a commit 586d9eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions WordPress/Classes/Utility/SharedStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum SharedStrings {

enum Error {
static let generic = NSLocalizedString("shared.error.geneirc", value: "Something went wrong", comment: "A generic error message")
static let refreshFailed = NSLocalizedString("shared.error.failiedToReloadData", value: "Failed to update data", comment: "A generic error title indicating that a screen failed to fetch the latest data")
}

enum Reader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ open class JetpackSpeedUpSiteSettingsViewController: UITableViewController {

@objc public convenience init(blog: Blog) {
self.init(style: .insetGrouped)

self.blog = blog
self.service = BlogJetpackSettingsService(coreDataStack: ContextManager.shared)
}
Expand All @@ -41,6 +42,7 @@ open class JetpackSpeedUpSiteSettingsViewController: UITableViewController {

open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

reloadViewModel()
refreshSettings()
}
Expand Down Expand Up @@ -77,7 +79,7 @@ open class JetpackSpeedUpSiteSettingsViewController: UITableViewController {

self.service.updateJetpackServeImagesFromOurServersModuleSettingForBlog(self.blog,
success: {},
failure: { [weak self] (_) in
failure: { [weak self] _ in
self?.refreshSettingsAfterSavingError()
})
}
Expand All @@ -86,14 +88,16 @@ open class JetpackSpeedUpSiteSettingsViewController: UITableViewController {
// MARK: - Persistance

fileprivate func refreshSettings() {
service.syncJetpackModulesForBlog(blog,
success: { [weak self] in
self?.reloadViewModel()
DDLogInfo("Reloaded Speed up site settings")
},
failure: { (error: Error?) in
DDLogError("Error while syncing blog Speed up site settings: \(String(describing: error))")
})
service.syncJetpackModulesForBlog(
blog,
success: { [weak self] in
self?.reloadViewModel()
DDLogInfo("Reloaded Speed up site settings")
},
failure: { (error: Error?) in
Notice(title: SharedStrings.Error.refreshFailed, message: error?.localizedDescription).post()
DDLogError("Error while syncing blog Speed up site settings: \(String(describing: error))")
})
}

fileprivate func refreshSettingsAfterSavingError() {
Expand Down

0 comments on commit 586d9eb

Please sign in to comment.