improve usage with STJson.TryDeserialize

This commit is contained in:
Bogdan 2024-01-16 04:52:49 +02:00
parent c37e3e4aa2
commit 3dfb8974dd
2 changed files with 17 additions and 4 deletions

View File

@ -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)

View File

@ -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;
}
}
}
}