Skip to content

Commit 9119f09

Browse files
authored
Do not call the failure block if the weak ref self is nil (#24638)
* Update error message * Do not call the failure block if the weak ref `self` is nil
1 parent 2908eae commit 9119f09

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

WordPress/Classes/ViewRelated/Blog/Blog Dashboard/BlogDashboardViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ extension BlogDashboardViewController {
231231

232232
private enum Strings {
233233
static let home = NSLocalizedString("Home", comment: "Title for the dashboard screen.")
234-
static let failureTitle = NSLocalizedString("Couldn't update. Check that you're online and refresh.", comment: "Content show when the dashboard fails to load")
234+
static let failureTitle = NSLocalizedString("Couldn't load data. Please refresh again later.", comment: "Content show when the dashboard fails to load")
235235
static let dismiss = NSLocalizedString(
236236
"blogDashboard.dismiss",
237237
value: "Dismiss",

WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Service/BlogDashboardService.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,24 @@ final class BlogDashboardService {
4747
let deviceID = remoteFeatureFlagStore.deviceID
4848

4949
remoteService.fetch(cards: cardsToFetch, forBlogID: dotComID, deviceId: deviceID, success: { [weak self] cardsDictionary in
50+
guard let self else {
51+
DDLogError("The BlogDashboardService instance is deallocated")
52+
return
53+
}
5054

51-
guard let cardsDictionary = self?.parseCardsForLocalContent(cardsDictionary, blog: blog) else {
55+
guard let cardsDictionary = self.parseCardsForLocalContent(cardsDictionary, blog: blog) else {
5256
failure?([])
5357
return
5458
}
5559

56-
if let cards = self?.decode(cardsDictionary, blog: blog) {
60+
if let cards = self.decode(cardsDictionary, blog: blog) {
5761

5862
blog.dashboardState.hasCachedData = true
5963
blog.dashboardState.failedToLoad = false
6064

61-
self?.persistence.persist(cards: cardsDictionary, for: dotComID)
62-
63-
guard let items = self?.parse(cards, blog: blog, dotComID: dotComID) else {
64-
failure?([])
65-
return
66-
}
65+
self.persistence.persist(cards: cardsDictionary, for: dotComID)
6766

67+
let items = self.parse(cards, blog: blog, dotComID: dotComID)
6868
completion(items)
6969
} else {
7070
blog.dashboardState.failedToLoad = true
@@ -73,9 +73,15 @@ final class BlogDashboardService {
7373

7474
}, failure: { [weak self] error in
7575
DDLogError("Failed to fetch Dashboard Cards: \(error.localizedDescription)")
76+
77+
guard let self else {
78+
DDLogError("The BlogDashboardService instance is deallocated")
79+
return
80+
}
81+
7682
blog.dashboardState.failedToLoad = true
77-
let items = self?.fetchLocal(blog: blog)
78-
failure?(items ?? [])
83+
let items = self.fetchLocal(blog: blog)
84+
failure?(items)
7985
})
8086
}
8187

0 commit comments

Comments
 (0)