1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 06:53:21 +08:00

Replace existing usage with helper method

This commit is contained in:
Dean Herbert 2022-03-30 23:57:19 +09:00
parent 5b3eb2d6f4
commit e0c125a628

View File

@ -1,13 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Logging;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -76,40 +72,23 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
Task task = itemToEdit != null ? client.EditPlaylistItem(multiplayerItem) : client.AddPlaylistItem(multiplayerItem); Task task = itemToEdit != null ? client.EditPlaylistItem(multiplayerItem) : client.AddPlaylistItem(multiplayerItem);
task.ContinueWith(t => task.FireAndForget(onSuccess: () => Schedule(() =>
{ {
Schedule(() => // If an error or server side trigger occurred this screen may have already exited by external means.
{ if (!this.IsCurrentScreen())
// If an error or server side trigger occurred this screen may have already exited by external means. return;
if (!this.IsCurrentScreen())
return;
loadingLayer.Hide(); loadingLayer.Hide();
this.Exit();
}), onError: _ => Schedule(() =>
{
// If an error or server side trigger occurred this screen may have already exited by external means.
if (!this.IsCurrentScreen())
return;
if (t.IsFaulted) loadingLayer.Hide();
{ Carousel.AllowSelection = true;
Exception exception = t.Exception; }));
if (exception is AggregateException ae)
exception = ae.InnerException;
Debug.Assert(exception != null);
string message = exception is HubException
// HubExceptions arrive with additional message context added, but we want to display the human readable message:
// "An unexpected error occurred invoking 'AddPlaylistItem' on the server.InvalidStateException: Can't enqueue more than 3 items at once."
// We generally use the message field for a user-parseable error (eventually to be replaced), so drop the first part for now.
? exception.Message.Substring(exception.Message.IndexOf(':') + 1).Trim()
: exception.Message;
Logger.Log(message, level: LogLevel.Important);
Carousel.AllowSelection = true;
return;
}
this.Exit();
});
});
} }
else else
{ {