download-manager icon indicating copy to clipboard operation
download-manager copied to clipboard

Allow to identify which DownloadBatchRequirementRule was violated if download fails

Open Konrad-Morawski opened this issue 4 years ago • 0 comments

Issue

While the library currently allows for setting up multiple requirement rules (DownloadBatchRequirementRule) that have to be met in order for the download to be successful, there is no way for determining which of the rules was violated, once it happens. The DownloadError instance that the calling code gets presented with only contains a general indication that some rule was violated (REQUIREMENT_RULE_VIOLATED). This poses a problem in scenario where the client code needs to set multiple rules, and its reaction to an error should differ depending on which rule was violated.

Real life example

Client app determines whether a requested download can be completed successfully based on whether there's enough storage on the device (rule 1). It also supports the user to set an arbitrary cap on the amount of storage available for downloads - a value customizable in the app settings. This requirement will be encoded as rule 2. Once a download can't come through, the expected reaction will differ.

  • If there's no available storage (rule 1), the user is presented with an error.
  • If the available storage is below the currently set limit (rule 2), the user is prompted to increase the limit in the settings.

Potential Solution

I am uploading my proposed implementation as a PR: https://github.com/novoda/download-manager/pull/524. Appreciate your feedback!

Konrad-Morawski avatar Oct 15 '19 12:10 Konrad-Morawski