mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 14:32:55 +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:
commit
f434d4d60f
@ -4,8 +4,11 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
@ -29,6 +32,15 @@ namespace osu.Game.Tests.Visual.Online
|
||||
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]
|
||||
public void TestArticlePage()
|
||||
{
|
||||
@ -56,7 +68,9 @@ namespace osu.Game.Tests.Visual.Online
|
||||
public void TestErrorPage()
|
||||
{
|
||||
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)
|
||||
|
@ -21,6 +21,8 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
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<APIWikiPage> wikiData = new Bindable<APIWikiPage>();
|
||||
@ -105,6 +107,9 @@ namespace osu.Game.Overlays
|
||||
if (e.NewValue == wikiData.Value?.Path)
|
||||
return;
|
||||
|
||||
if (e.NewValue == "error")
|
||||
return;
|
||||
|
||||
cancellationToken?.Cancel();
|
||||
request?.Cancel();
|
||||
|
||||
@ -118,7 +123,11 @@ namespace osu.Game.Overlays
|
||||
Loading.Show();
|
||||
|
||||
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);
|
||||
}
|
||||
@ -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/",
|
||||
$"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()
|
||||
|
Loading…
Reference in New Issue
Block a user