RestClient icon indicating copy to clipboard operation
RestClient copied to clipboard

How to stop downloading files on error response?

Open KingZee opened this issue 1 year ago • 1 comments

    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?

KingZee avatar Oct 24 '24 19:10 KingZee