Remove redundant variable, handle all request failures

This commit is contained in:
naoey
2019-06-19 19:43:09 +05:30
parent 26c32ceeb1
commit 4b46601eae
2 changed files with 16 additions and 14 deletions

View File

@ -94,16 +94,7 @@ namespace osu.Game.Database
}, TaskCreationOptions.LongRunning); }, TaskCreationOptions.LongRunning);
}; };
request.Failure += error => request.Failure += error => handleRequestFailure(request, notification, error);
{
DownloadFailed?.Invoke(request);
if (error is OperationCanceledException) return;
notification.State = ProgressNotificationState.Cancelled;
Logger.Error(error, $"{HumanisedModelName.Titleize()} download failed!");
currentDownloads.Remove(request);
};
notification.CancelRequested += () => notification.CancelRequested += () =>
{ {
@ -122,14 +113,27 @@ namespace osu.Game.Database
{ {
request.Perform(api); request.Perform(api);
} }
catch catch (Exception e)
{ {
// 404s (and maybe other failures) don't fire request.Failure so for now they handled here as well
handleRequestFailure(request, notification, e);
} }
}, TaskCreationOptions.LongRunning); }, TaskCreationOptions.LongRunning);
DownloadBegan?.Invoke(request); DownloadBegan?.Invoke(request);
} }
private void handleRequestFailure(ArchiveDownloadRequest<TModel> req, ProgressNotification notification, Exception e)
{
DownloadFailed?.Invoke(req);
if (e is OperationCanceledException) return;
notification.State = ProgressNotificationState.Cancelled;
Logger.Error(e, $"{HumanisedModelName.Titleize()} download failed!");
currentDownloads.Remove(req);
}
private class DownloadNotification : ProgressNotification private class DownloadNotification : ProgressNotification
{ {
public override bool IsImportant => false; public override bool IsImportant => false;

View File

@ -8,15 +8,13 @@ namespace osu.Game.Online.API.Requests
public class DownloadBeatmapSetRequest : ArchiveDownloadRequest<BeatmapSetInfo> public class DownloadBeatmapSetRequest : ArchiveDownloadRequest<BeatmapSetInfo>
{ {
private readonly bool noVideo; private readonly bool noVideo;
private readonly BeatmapSetInfo set;
public DownloadBeatmapSetRequest(BeatmapSetInfo set, bool noVideo) public DownloadBeatmapSetRequest(BeatmapSetInfo set, bool noVideo)
: base(set) : base(set)
{ {
this.noVideo = noVideo; this.noVideo = noVideo;
this.set = set;
} }
protected override string Target => $@"beatmapsets/{set.OnlineBeatmapSetID}/download{(noVideo ? "?noVideo=1" : "")}"; protected override string Target => $@"beatmapsets/{Model.OnlineBeatmapSetID}/download{(noVideo ? "?noVideo=1" : "")}";
} }
} }