Skip to content

Commit

Permalink
Merge pull request #2285 from CruGlobal/GT-2408-fix-bug-in-language-d…
Browse files Browse the repository at this point in the history
…ownloader-when-no-network-connection

GT-2457 Fix bug in language downloader when download fails
  • Loading branch information
levieggertcru authored Oct 3, 2024
2 parents 44421bb + caf4a40 commit 76231a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
8 changes: 0 additions & 8 deletions godtools.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11246,13 +11246,6 @@
path = Subviews;
sourceTree = "<group>";
};
D40D77BD2AB23183008D3642 /* Models */ = {
isa = PBXGroup;
children = (
);
path = Models;
sourceTree = "<group>";
};
D4159D512C2CE0240088A203 /* PersistUserToolLanguageSettings */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -11473,7 +11466,6 @@
D40D77B42AA900FB008D3642 /* ToolStringKeys.swift */,
45920D4E2A8D3D1800E336A8 /* ToolsView.swift */,
45920D4D2A8D3D1800E336A8 /* ToolsViewModel.swift */,
D40D77BD2AB23183008D3642 /* Models */,
45DD84C42A8BD53E0066A020 /* Subviews */,
);
path = Tools;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,31 @@ class DownloadToolLanguageRepository: DownloadToolLanguageRepositoryInterface {

return toolLanguageDownloader
.downloadToolLanguagePublisher(languageId: languageId)
.map {
.catch { (downloadError: Error) -> AnyPublisher<ToolDownloaderDataModel, Error> in

let progress = $0.progress
return self.downloadedLanguagesRepository.deleteDownloadedLanguagePublisher(languageId: languageId)
.catch { (deleteError: Error) -> AnyPublisher<Void, Error> in

assertionFailure("Failed to delete object in RealmDatabase. \(deleteError.localizedDescription)")

return Fail(error: downloadError)
.eraseToAnyPublisher()
}
.flatMap({ (void: Void) -> AnyPublisher<ToolDownloaderDataModel, Error> in
return Fail(error: downloadError)
.eraseToAnyPublisher()
})
.eraseToAnyPublisher()
}
.map { (dataModel: ToolDownloaderDataModel) in

let progress = dataModel.progress

if progress >= 1 {
self.downloadedLanguagesRepository.storeDownloadedLanguage(languageId: languageId, downloadComplete: true)
}

return $0.progress
return dataModel.progress
}
.eraseToAnyPublisher()
}
Expand Down

0 comments on commit 76231a3

Please sign in to comment.