bezzad / Downloader

Fast, cross-platform and reliable multipart downloader with asynchronous progress events for .NET applications.
MIT License
1.25k stars 193 forks source link

No error when server responds with 404 #146

Closed eriktack closed 8 months ago

eriktack commented 1 year ago

Maybe im too stupid to understand how this works, but if I use the DownloadService without any custom config on a url that return statuscode 404 like so: var service = new DownloadService (); await service.DownloadFileTaskAsync(url, tempFileName);

Then the downloader just saves a 0 byte file without giving any warning or error. this didnt used to happen with version 2.0.0, then I got an exception and could handle it.

bezzad commented 1 year ago

Hi @eriktack, no problem if you have any questions feel free to ask. the Downloader has an event named DownloadFileCompleted which sends events of completion reasons to the handler. If your download has any error, this event sends an error message in arguments.

var downloader = new DownloadService ();
downloader.DownloadFileCompleted += OnDownloadFileCompleted;

private static void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
            if (e.Cancelled)
            {
                // download canceled
            }
            else if (e.Error != null)
            {
                // Error occurred
            }
            else
            {
                // downloaded successfully
            }
}