1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 19:22:56 +08:00

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
No known key found for this signature in database
GPG Key ID: 670DA9BE3DF7EE60
2 changed files with 16 additions and 14 deletions

View File

@ -94,16 +94,7 @@ namespace osu.Game.Database
}, TaskCreationOptions.LongRunning);
};
request.Failure += error =>
{
DownloadFailed?.Invoke(request);
if (error is OperationCanceledException) return;
notification.State = ProgressNotificationState.Cancelled;
Logger.Error(error, $"{HumanisedModelName.Titleize()} download failed!");
currentDownloads.Remove(request);
};
request.Failure += error => handleRequestFailure(request, notification, error);
notification.CancelRequested += () =>
{
@ -122,14 +113,27 @@ namespace osu.Game.Database
{
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);
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
{
public override bool IsImportant => false;

View File

@ -8,15 +8,13 @@ namespace osu.Game.Online.API.Requests
public class DownloadBeatmapSetRequest : ArchiveDownloadRequest<BeatmapSetInfo>
{
private readonly bool noVideo;
private readonly BeatmapSetInfo set;
public DownloadBeatmapSetRequest(BeatmapSetInfo set, bool noVideo)
: base(set)
{
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" : "")}";
}
}