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

Avoid deserialisation JSON request content when error is not present (or not relevant)

This commit is contained in:
Dean Herbert 2021-07-28 20:13:40 +09:00
parent 2b107d624a
commit 1ed4fdd5f5

View File

@ -171,19 +171,24 @@ namespace osu.Game.Online.API
WebRequest?.Abort();
string responseString = WebRequest?.GetResponseString();
if (!string.IsNullOrEmpty(responseString))
// in the case of a cancellation we don't care about whether there's an error in the response.
if (!(e is OperationCanceledException))
{
try
{
// attempt to decode a displayable error string.
var error = JsonConvert.DeserializeObject<DisplayableError>(responseString);
if (error != null)
e = new APIException(error.ErrorMessage, e);
}
catch
string responseString = WebRequest?.GetResponseString();
// naive check whether there's an error in the response to avoid unnecessary JSON deserialisation.
if (!string.IsNullOrEmpty(responseString) && responseString.Contains(@"""error"""))
{
try
{
// attempt to decode a displayable error string.
var error = JsonConvert.DeserializeObject<DisplayableError>(responseString);
if (error != null)
e = new APIException(error.ErrorMessage, e);
}
catch
{
}
}
}