mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-17 07:13:09 +01:00
Changed error detection logic, fixes #7
* removed "json.Contains("error")" - lol
This commit is contained in:
parent
015362fc81
commit
f2b0875503
@ -89,14 +89,6 @@ public static string FormatQueryParameters(IEnumerable<KeyValuePair<string, stri
|
||||
|
||||
public static bool IsResponseValid(string json, out LastFmApiError error)
|
||||
{
|
||||
// hmmm
|
||||
if (json.Length > 1 && !json.Contains("error"))
|
||||
{
|
||||
error = LastFmApiError.None;
|
||||
return true;
|
||||
}
|
||||
|
||||
error = LastFmApiError.Unknown;
|
||||
JObject jo;
|
||||
try
|
||||
{
|
||||
@ -104,11 +96,22 @@ public static bool IsResponseValid(string json, out LastFmApiError error)
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
error = LastFmApiError.Unknown;
|
||||
return false;
|
||||
}
|
||||
|
||||
var code = jo.Value<int>("error");
|
||||
var codeString = jo.Value<string>("error");
|
||||
if (string.IsNullOrWhiteSpace(codeString) && json.Length > 1)
|
||||
{
|
||||
error = LastFmApiError.None;
|
||||
return true;
|
||||
}
|
||||
|
||||
error = LastFmApiError.Unknown;
|
||||
|
||||
int code;
|
||||
if (Int32.TryParse(codeString, out code))
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case 2:
|
||||
@ -154,6 +157,7 @@ public static bool IsResponseValid(string json, out LastFmApiError error)
|
||||
error = LastFmApiError.RateLimited;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user