kudoleh / iOS-Clean-Architecture-MVVM

Template iOS app using Clean Architecture and MVVM. Includes DIContainer, FlowCoordinator, DTO, Response Caching and one of the views in SwiftUI
https://tech.olx.com/clean-architecture-and-mvvm-on-ios-c9d167d9f5b3
3.91k stars 672 forks source link

Is there a better way? #8

Closed user-mobil closed 4 years ago

user-mobil commented 4 years ago

https://github.com/kudoleh/iOS-Clean-Architecture-MVVM/blob/a5afd66e5910db61815af7f84369f06a1fd808bb/ExampleMVVM/Data/PersistentStorages/CoreDataStorage/CoreDataStorage.swift#L25

Hi. I really appreciate your repository. I was wondering what you believe the best way to solve or propagate errors in this clean architecture would be, for a shipping application.

kudoleh commented 4 years ago

Hi, Thank you! Great question!

How to handle error depends on how critical error and what kind or error is. In this case I would log this error in Firebase Crashlytics because I use persistence only for persisting(caching) response and recent queries which is not critical functionally, and app can continue working and providing the key functionality, logging this error will be enough and then inspecting it in Firebase and fixing it.

Then examples of error handling and propagations you can find here:

    private func handle(error: Error) {
        self.error.value = error.isInternetConnectionError ?
            NSLocalizedString("No internet connection", comment: "") :
            NSLocalizedString("Failed loading movies", comment: "")
    }

How to handle an error and on what level depends on the kind of error.

For all our errors we show to users only more generic errors like: "Something went wrong, we are working on fixing it" or connection error. And internally we handle them and log them in Crashlytics.

Also these Examples show that use of Result, Result.MapError and throw are used to propagate and handle errors.

user-mobil commented 4 years ago

Thank you!! Very much appreciated.