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

Best way to catch HTTP errors #466

Closed matecode closed 5 years ago

matecode commented 5 years ago

Hi team,

what is your recommended way to catch http errors, e.g. 401 (in my case) ... It seems that the lib always try to download again, even if there is a 401 or 404.

Do i miss something to catch it? Maybe my question is related to #458 Thanks for your help!

Mecharyry commented 5 years ago

Hi @matecode,

From what I remember the errors should come batched in the waiting for network status but I can see that they are not. It seems like the request is most likely failing when attempting to get the totalSize of a given batch, at which point the download is swallowed and transitions to the waiting for network state without the error.

This is indeed a problem, we need to expose a similar status on this sizeRequest that we do for the rest of the download. We'll try and get this fixed as soon as possible, sorry about that!

matecode commented 5 years ago

@Mecharyry thanks for the fast reply ...

We'll try and get this fixed as soon as possible,

Cool, i'm staying tuned and can't wait to replace the system DownloadManager ;)

matecode commented 5 years ago

Any news on this? For me it's a blocking error if I cannot handle HTTP errors.

Mecharyry commented 5 years ago

Hi @matecode I'm sorry but none of the maintainers have had much time to look at the download-manager recently. I'm really sorry for this, it's not the situation I want you to be in.

I'm going to commit to having an answer back to you in a weeks time 7th February. Hopefully by that date I will have patched the issue and have it out in production. Again, I am really sorry that you are in this situation.

Mecharyry commented 5 years ago

Hi again @matecode, I've spent the last couple of evenings looking into the issue. See here for the current progress.

It seems that the FileSizeRequester does not propagate errors of any kind. This is further compounded by the problem in that the DownloadManager is fine receiving 0 as a result of this FileSizeRequest 😬 which, as you have already stated, results in a WAITING_FOR_NETWORK status.

I've got the point where I have introduced an explicit FileSizeResult which can be either a success or a failure. I now need to propagate this into the DownloadManager and ensure that all of our scenarios work. I'll try and keep this updated as I work on this further.

Mecharyry commented 5 years ago

Hey @zegnus it might be worth you having a look at my branch 😄 just on the off chance you have any ideas 😄

Mecharyry commented 5 years ago

@matecode would you be interested in trying out this branch -> https://github.com/novoda/download-manager/compare/develop...DLM-466/http_errors?expand=1

I think it might solve the problems you have been having but I do not have any demo / scenario to test it against. Would you be able to try it using mavenLocal? It would be great if you could let me know so I can come up with an alternative plan if you are unable. Thanks!

Mecharyry commented 5 years ago

Collapsing this into #483. This requires more careful analysis.