Changed error detection logic, fixes #7

* removed "json.Contains("error")"  - lol
This commit is contained in:
Rikki Tooley 2013-09-11 03:37:55 +01:00
parent 015362fc81
commit f2b0875503

View File

@ -89,14 +89,6 @@ public static string FormatQueryParameters(IEnumerable<KeyValuePair<string, stri
public static bool IsResponseValid(string json, out LastFmApiError error) 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; JObject jo;
try try
{ {
@ -104,11 +96,22 @@ public static bool IsResponseValid(string json, out LastFmApiError error)
} }
catch (JsonException) catch (JsonException)
{ {
error = LastFmApiError.Unknown;
return false; 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) switch (code)
{ {
case 2: case 2:
@ -154,6 +157,7 @@ public static bool IsResponseValid(string json, out LastFmApiError error)
error = LastFmApiError.RateLimited; error = LastFmApiError.RateLimited;
break; break;
} }
}
return false; return false;
} }