mirror of https://github.com/Jackett/Jackett
improve usage with STJson.TryDeserialize
This commit is contained in:
parent
c37e3e4aa2
commit
3dfb8974dd
|
@ -144,11 +144,9 @@ namespace Jackett.Common.Indexers
|
|||
throw new TooManyRequestsException("Rate limited", indexerResponse);
|
||||
}
|
||||
|
||||
if (response.StartsWith("{\"error\""))
|
||||
if (response.StartsWith("{\"error\"") && STJson.TryDeserialize<FileListErrorResponse>(response, out var errorResponse))
|
||||
{
|
||||
var error = STJson.Deserialize<FileListErrorResponse>(response).Error;
|
||||
|
||||
throw new ExceptionWithConfigData(error, configData);
|
||||
throw new ExceptionWithConfigData(errorResponse.Error, configData);
|
||||
}
|
||||
|
||||
if (indexerResponse.Status != HttpStatusCode.OK)
|
||||
|
|
|
@ -32,5 +32,20 @@ namespace Jackett.Common.Serializer
|
|||
{
|
||||
return JsonSerializer.Deserialize<T>(json, _SerializerSettings);
|
||||
}
|
||||
|
||||
public static bool TryDeserialize<T>(string json, out T result)
|
||||
where T : new()
|
||||
{
|
||||
try
|
||||
{
|
||||
result = Deserialize<T>(json);
|
||||
return true;
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
result = default(T);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue