mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 00:09:55 +09:00
Get error message from server
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Framework.Logging;
|
||||
|
||||
@ -112,6 +113,22 @@ namespace osu.Game.Online.API
|
||||
cancelled = true;
|
||||
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);
|
||||
pendingFailure = () => Failure?.Invoke(e);
|
||||
checkAndScheduleFailure();
|
||||
@ -129,6 +146,12 @@ namespace osu.Game.Online.API
|
||||
pendingFailure = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
private class DisplayableError
|
||||
{
|
||||
[JsonProperty("error")]
|
||||
public string ErrorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void APIFailureHandler(Exception e);
|
||||
|
Reference in New Issue
Block a user