Skip to content

Commit

Permalink
Handle missing download file
Browse files Browse the repository at this point in the history
  • Loading branch information
albyrock87 committed Jan 23, 2025
1 parent 779ec40 commit dda63ad
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,20 @@ public override void DidFinishDownloading(NSUrlSession session, NSUrlSessionDown
// We should be good with a temporary file path considering we're going to read it right away.
var locationPath = location.Path;
handle.ResponseContentFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N") + ".nsresponse");
File.Move(locationPath!, handle.ResponseContentFile, true);

// This might have taken a while, so let's update the last completed task timestamp
_lastCompletedTaskTimestamp = Stopwatch.GetTimestamp();
try
{
File.Move(locationPath!, handle.ResponseContentFile, true);
}
catch (Exception ex)
{
handle.ResponseCompletionSource.TrySetException(new HttpRequestException("Temporary response file is gone", ex));
return;
}
finally
{
// This might have taken a while, so let's update the last completed task timestamp
_lastCompletedTaskTimestamp = Stopwatch.GetTimestamp();
}

var httpResponseMessage = new HttpResponseMessage(task.GetHttpStatusCode())
{
Expand Down

0 comments on commit dda63ad

Please sign in to comment.