0

假设我的应用程序中有这个架构 建筑学

我的问题是处理错误的最佳时间是什么时候?

  1. 我是不是应该让网络源和缓存源抛出错误,我们在repository层处理所有可能的错误
  2. 我应该处理特定于框架的错误,并返回一个密封的类,该类是网络调用错误还是成功
4

1 回答 1

0

Depends on the use case

  • If user is expecting data, then you need to send the errors all the way to your UI to notify user to make sure user won't just see a blank screen or experience unexpected UI. You can sealed classes in Kotlin for this case.
  • If you are fetching something which user is not aware of, like syncing data from remote to Local cache in background, In cases like this user is not aware/ do not care about errors, your app should handle. Ideal way is to check in handle error in repository, if something fails, retrying it there or fetching data from alternate source etc.
  • Third case would be handling at multiple levels, say you are fetching data from network, it failed, you can handle retry logic in repository level and after you exhaust your retry attempts but still it is failing then you need to acknowledge user as he might be expecting some thing to show up.
于 2021-02-18T07:21:56.390 回答