Skip to content

How to stop downloading files on error response? #251

@KingZee

Description

@KingZee
    public void DownloadFile(string fileName)
    {
        string url = mainLink + "files/" + fileName;
        string localPath = Path.Combine(DataManager.videosFolder + fileName);

        if (!System.IO.File.Exists(localPath))
        {
            RestClient.Get(new RequestHelper
            {
                Uri = url,
                DownloadHandler = new DownloadHandlerFile(Path.Combine(localPath)),
                Timeout = 13,
                Retries = 0,
                IgnoreHttpException = false
            }).Then(response =>
            {
                if (response.Request.downloadHandler.isDone)
                {
                    Popup.main.DisplayMessage(Popup.Style.Blue, "Completed video download!", false);
                }
            }).Catch(ErrorHandler);
        }
    }

On an http exception ErrorHandler is called and code works, but the errored response is downloaded and stored as a file (Cannot GET /files/xx), do I have to delete it every time or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions