Avistaz response improvements

This commit is contained in:
Bakerboy448 2023-01-05 12:09:07 -06:00
parent 3dfbfd07dd
commit 5e15054329
2 changed files with 20 additions and 12 deletions

View file

@ -98,6 +98,12 @@ protected override async Task<ValidationFailure> TestConnection()
var jsonResponse = new HttpResponse<AvistazErrorResponse>(ex.Response); var jsonResponse = new HttpResponse<AvistazErrorResponse>(ex.Response);
return new ValidationFailure(string.Empty, jsonResponse.Resource?.Message ?? "Unauthorized request to indexer"); return new ValidationFailure(string.Empty, jsonResponse.Resource?.Message ?? "Unauthorized request to indexer");
} }
else if (ex.Response.StatusCode == HttpStatusCode.TooManyRequests)
{
_logger.Warn(ex, "Too Many Requests");
return new ValidationFailure(string.Empty, "Too Many Requests");
}
else else
{ {
_logger.Warn(ex, "Unable to connect to indexer"); _logger.Warn(ex, "Unable to connect to indexer");

View file

@ -24,24 +24,26 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
{ {
var torrentInfos = new List<TorrentInfo>(); var torrentInfos = new List<TorrentInfo>();
if (indexerResponse.HttpResponse.StatusCode == HttpStatusCode.NotFound) if (!indexerResponse.HttpResponse.Headers.ContentType.Contains(HttpAccept.Json.Value))
{ {
return torrentInfos.ToArray(); throw new IndexerException(indexerResponse, $"Unexpected response header {indexerResponse.HttpResponse.Headers.ContentType} from API request, expected {HttpAccept.Json.Value}");
}
if (indexerResponse.HttpResponse.StatusCode == HttpStatusCode.TooManyRequests)
{
throw new RequestLimitReachedException(indexerResponse, "API Request Limit Reached");
} }
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
{ {
throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponse.HttpResponse.StatusCode} code from API request"); if (indexerResponse.HttpResponse.StatusCode == HttpStatusCode.NotFound)
{
// No results found
return torrentInfos.ToArray();
} }
if (!indexerResponse.HttpResponse.Headers.ContentType.Contains(HttpAccept.Json.Value)) HttpResponse<AvistazErrorResponse> jsonErrorResponse = new HttpResponse<AvistazErrorResponse>(indexerResponse.HttpResponse);
if (indexerResponse.HttpResponse.StatusCode == HttpStatusCode.Unauthorized)
{ {
throw new IndexerException(indexerResponse, $"Unexpected response header {indexerResponse.HttpResponse.Headers.ContentType} from API request, expected {HttpAccept.Json.Value}"); throw new IndexerAuthException(string.Empty, jsonErrorResponse.Resource?.Message ?? "Unauthorized request to indexer");
}
throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponse.HttpResponse.StatusCode} code from API request");
} }
var jsonResponse = new HttpResponse<AvistazResponse>(indexerResponse.HttpResponse); var jsonResponse = new HttpResponse<AvistazResponse>(indexerResponse.HttpResponse);