Only show user displayable portion of server errors when seleting a song in multiplayer

This commit is contained in:
Dean Herbert 2021-11-19 13:58:03 +09:00
parent 6ebe54b183
commit 284e554cbf
1 changed files with 22 additions and 4 deletions

View File

@ -1,6 +1,9 @@
// 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.
using System;
using System.Diagnostics;
using Microsoft.AspNetCore.SignalR;
using osu.Framework.Allocation;
using osu.Framework.Logging;
using osu.Framework.Screens;
@ -60,13 +63,28 @@ protected override void SelectItem(PlaylistItem item)
{
loadingLayer.Hide();
if (t.IsCompletedSuccessfully)
this.Exit();
else
if (t.IsFaulted)
{
Logger.Log($"Could not use current beatmap ({t.Exception?.Message})", level: LogLevel.Important);
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();
});
});
}