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,55 +96,67 @@ public static bool IsResponseValid(string json, out LastFmApiError error)
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
error = LastFmApiError.Unknown;
|
||||
return false;
|
||||
}
|
||||
|
||||
var code = jo.Value<int>("error");
|
||||
|
||||
switch (code)
|
||||
var codeString = jo.Value<string>("error");
|
||||
if (string.IsNullOrWhiteSpace(codeString) && json.Length > 1)
|
||||
{
|
||||
case 2:
|
||||
error = LastFmApiError.ServiceServiceWhereArtThou;
|
||||
break;
|
||||
case 3:
|
||||
error = LastFmApiError.BadMethod;
|
||||
break;
|
||||
case 4:
|
||||
error = LastFmApiError.BadAuth;
|
||||
break;
|
||||
case 5:
|
||||
error = LastFmApiError.BadFormat;
|
||||
break;
|
||||
case 6:
|
||||
error = LastFmApiError.MissingParameters;
|
||||
break;
|
||||
case 7:
|
||||
error = LastFmApiError.BadResource;
|
||||
break;
|
||||
case 8:
|
||||
error = LastFmApiError.Failure;
|
||||
break;
|
||||
case 9:
|
||||
error = LastFmApiError.SessionExpired;
|
||||
break;
|
||||
case 10:
|
||||
error = LastFmApiError.BadApiKey;
|
||||
break;
|
||||
case 11:
|
||||
error = LastFmApiError.ServiceDown;
|
||||
break;
|
||||
case 13:
|
||||
error = LastFmApiError.BadMethodSignature;
|
||||
break;
|
||||
case 16:
|
||||
error = LastFmApiError.TemporaryFailure;
|
||||
break;
|
||||
case 26:
|
||||
error = LastFmApiError.KeySuspended;
|
||||
break;
|
||||
case 29:
|
||||
error = LastFmApiError.RateLimited;
|
||||
break;
|
||||
error = LastFmApiError.None;
|
||||
return true;
|
||||
}
|
||||
|
||||
error = LastFmApiError.Unknown;
|
||||
|
||||
int code;
|
||||
if (Int32.TryParse(codeString, out code))
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case 2:
|
||||
error = LastFmApiError.ServiceServiceWhereArtThou;
|
||||
break;
|
||||
case 3:
|
||||
error = LastFmApiError.BadMethod;
|
||||
break;
|
||||
case 4:
|
||||
error = LastFmApiError.BadAuth;
|
||||
break;
|
||||
case 5:
|
||||
error = LastFmApiError.BadFormat;
|
||||
break;
|
||||
case 6:
|
||||
error = LastFmApiError.MissingParameters;
|
||||
break;
|
||||
case 7:
|
||||
error = LastFmApiError.BadResource;
|
||||
break;
|
||||
case 8:
|
||||
error = LastFmApiError.Failure;
|
||||
break;
|
||||
case 9:
|
||||
error = LastFmApiError.SessionExpired;
|
||||
break;
|
||||
case 10:
|
||||
error = LastFmApiError.BadApiKey;
|
||||
break;
|
||||
case 11:
|
||||
error = LastFmApiError.ServiceDown;
|
||||
break;
|
||||
case 13:
|
||||
error = LastFmApiError.BadMethodSignature;
|
||||
break;
|
||||
case 16:
|
||||
error = LastFmApiError.TemporaryFailure;
|
||||
break;
|
||||
case 26:
|
||||
error = LastFmApiError.KeySuspended;
|
||||
break;
|
||||
case 29:
|
||||
error = LastFmApiError.RateLimited;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user