novoda / download-manager

A library that handles long-running downloads, handling the network interactions and retrying downloads automatically after failures
Apache License 2.0
483 stars 63 forks source link

Allow to identify which DownloadBatchRequirementRule was violated if download fails #525

Open Konrad-Morawski opened 4 years ago

Konrad-Morawski commented 4 years ago

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.

Potential Solution

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