mirror of
https://github.com/ppy/osu.git
synced 2025-01-19 06:32:55 +08:00
Merge pull request #14045 from peppy/avoid-unnecessary-error-deserialisation
Avoid deserialisation JSON request content when error is not present (or not relevant)
This commit is contained in:
commit
5144bf8354
@ -171,19 +171,24 @@ namespace osu.Game.Online.API
|
|||||||
|
|
||||||
WebRequest?.Abort();
|
WebRequest?.Abort();
|
||||||
|
|
||||||
string responseString = WebRequest?.GetResponseString();
|
// in the case of a cancellation we don't care about whether there's an error in the response.
|
||||||
|
if (!(e is OperationCanceledException))
|
||||||
if (!string.IsNullOrEmpty(responseString))
|
|
||||||
{
|
{
|
||||||
try
|
string responseString = WebRequest?.GetResponseString();
|
||||||
{
|
|
||||||
// attempt to decode a displayable error string.
|
// naive check whether there's an error in the response to avoid unnecessary JSON deserialisation.
|
||||||
var error = JsonConvert.DeserializeObject<DisplayableError>(responseString);
|
if (!string.IsNullOrEmpty(responseString) && responseString.Contains(@"""error"""))
|
||||||
if (error != null)
|
|
||||||
e = new APIException(error.ErrorMessage, e);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// attempt to decode a displayable error string.
|
||||||
|
var error = JsonConvert.DeserializeObject<DisplayableError>(responseString);
|
||||||
|
if (error != null)
|
||||||
|
e = new APIException(error.ErrorMessage, e);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user