1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:12:57 +08:00

Merge pull request #21772 from peppy/upgrade-guide-help

Fix wiki overlay showing error message when load is cancelled
This commit is contained in:
Bartłomiej Dach 2022-12-23 17:56:29 +01:00 committed by GitHub
commit f434d4d60f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View File

@ -4,8 +4,11 @@
#nullable disable #nullable disable
using System; using System;
using System.Linq;
using System.Net; using System.Net;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
@ -29,6 +32,15 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Show main page", () => wiki.Show()); AddStep("Show main page", () => wiki.Show());
} }
[Test]
public void TestCancellationDoesntShowError()
{
AddStep("Show main page", () => wiki.Show());
AddStep("Show another page", () => wiki.ShowPage("Article_styling_criteria/Formatting"));
AddUntilStep("Current path is not error", () => wiki.CurrentPath != "error");
}
[Test] [Test]
public void TestArticlePage() public void TestArticlePage()
{ {
@ -56,7 +68,9 @@ namespace osu.Game.Tests.Visual.Online
public void TestErrorPage() public void TestErrorPage()
{ {
setUpWikiResponse(responseArticlePage); setUpWikiResponse(responseArticlePage);
AddStep("Show Error Page", () => wiki.ShowPage("Error")); AddStep("Show nonexistent page", () => wiki.ShowPage("This_page_will_error_out"));
AddUntilStep("Wait for error page", () => wiki.CurrentPath == "error");
AddUntilStep("Error message correct", () => wiki.ChildrenOfType<SpriteText>().Any(text => text.Text == "\"This_page_will_error_out\"."));
} }
private void setUpWikiResponse(APIWikiPage r, string redirectionPath = null) private void setUpWikiResponse(APIWikiPage r, string redirectionPath = null)

View File

@ -21,6 +21,8 @@ namespace osu.Game.Overlays
{ {
private const string index_path = @"main_page"; private const string index_path = @"main_page";
public string CurrentPath => path.Value;
private readonly Bindable<string> path = new Bindable<string>(index_path); private readonly Bindable<string> path = new Bindable<string>(index_path);
private readonly Bindable<APIWikiPage> wikiData = new Bindable<APIWikiPage>(); private readonly Bindable<APIWikiPage> wikiData = new Bindable<APIWikiPage>();
@ -105,6 +107,9 @@ namespace osu.Game.Overlays
if (e.NewValue == wikiData.Value?.Path) if (e.NewValue == wikiData.Value?.Path)
return; return;
if (e.NewValue == "error")
return;
cancellationToken?.Cancel(); cancellationToken?.Cancel();
request?.Cancel(); request?.Cancel();
@ -118,7 +123,11 @@ namespace osu.Game.Overlays
Loading.Show(); Loading.Show();
request.Success += response => Schedule(() => onSuccess(response)); request.Success += response => Schedule(() => onSuccess(response));
request.Failure += _ => Schedule(onFail); request.Failure += ex =>
{
if (ex is not OperationCanceledException)
Schedule(onFail, request.Path);
};
api.PerformAsync(request); api.PerformAsync(request);
} }
@ -146,10 +155,11 @@ namespace osu.Game.Overlays
} }
} }
private void onFail() private void onFail(string originalPath)
{ {
path.Value = "error";
LoadDisplay(articlePage = new WikiArticlePage($@"{api.WebsiteRootUrl}/wiki/", LoadDisplay(articlePage = new WikiArticlePage($@"{api.WebsiteRootUrl}/wiki/",
$"Something went wrong when trying to fetch page \"{path.Value}\".\n\n[Return to the main page](Main_Page).")); $"Something went wrong when trying to fetch page \"{originalPath}\".\n\n[Return to the main page](Main_Page)."));
} }
private void showParentPage() private void showParentPage()