Skip to content

Commit

Permalink
fix refresh not working
Browse files Browse the repository at this point in the history
  • Loading branch information
n3d1117 committed May 14, 2023
1 parent 1fb9550 commit ef1d278
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Stats/App/Data/NetworkDataLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import Models
}

func load() async {
if persistenceService.persistedResponse != .empty {
state = .success(persistenceService.persistedResponse)
}
do {
let response = try await networkService.loadData()
state = .success(response)
try await persistenceService.set(response)
} catch {
if persistenceService.persistedResponse == .empty {
let cachedResponse = persistenceService.persistedResponse
if cachedResponse == .empty {
state = .failed(error)
} else {
state = .success(cachedResponse)
}
}
}
Expand Down

0 comments on commit ef1d278

Please sign in to comment.