1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 03:02:55 +08:00

Get error message from server

This commit is contained in:
Dean Herbert 2019-11-12 19:34:20 +09:00
parent f04d7f733f
commit 58df6930b2
2 changed files with 28 additions and 8 deletions

View File

@ -2,6 +2,7 @@
// 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;
using Newtonsoft.Json;
using osu.Framework.IO.Network; using osu.Framework.IO.Network;
using osu.Framework.Logging; using osu.Framework.Logging;
@ -112,6 +113,22 @@ namespace osu.Game.Online.API
cancelled = true; cancelled = true;
WebRequest?.Abort(); WebRequest?.Abort();
string responseString = WebRequest?.ResponseString;
if (!string.IsNullOrEmpty(responseString))
{
try
{
// attempt to decode a displayable error string.
var error = JsonConvert.DeserializeObject<DisplayableError>(responseString);
if (error != null)
e = new Exception(error.ErrorMessage, e);
}
catch
{
}
}
Logger.Log($@"Failing request {this} ({e})", LoggingTarget.Network); Logger.Log($@"Failing request {this} ({e})", LoggingTarget.Network);
pendingFailure = () => Failure?.Invoke(e); pendingFailure = () => Failure?.Invoke(e);
checkAndScheduleFailure(); checkAndScheduleFailure();
@ -129,6 +146,12 @@ namespace osu.Game.Online.API
pendingFailure = null; pendingFailure = null;
return true; return true;
} }
private class DisplayableError
{
[JsonProperty("error")]
public string ErrorMessage;
}
} }
public delegate void APIFailureHandler(Exception e); public delegate void APIFailureHandler(Exception e);

View File

@ -71,15 +71,12 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
request.Success += () => favourited.Value = !favourited.Value; request.Success += () => favourited.Value = !favourited.Value;
request.Failure += exception => request.Failure += exception =>
{ {
if (exception.Message == "UnprocessableEntity") notifications.Post(new SimpleNotification
{ {
notifications.Post(new SimpleNotification Text = exception.Message,
{ Icon = FontAwesome.Solid.Times,
Text = @"You have too many favourited beatmaps! Please unfavourite some before trying again.", });
Icon = FontAwesome.Solid.Times, loading.Hide();
});
loading.Hide();
}
}; };
api.Queue(request); api.Queue(request);
}; };