From a637677ec46292a838d111d73fd57541daee9871 Mon Sep 17 00:00:00 2001 From: Qstick Date: Fri, 4 Feb 2022 22:51:55 -0600 Subject: [PATCH] New: (Avistaz) Better error reporting for unauthorized tests Fixes #822 --- .../Indexers/Definitions/Avistaz/AvistazApi.cs | 5 +++++ .../Indexers/Definitions/Avistaz/AvistazBase.cs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazApi.cs b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazApi.cs index fc22adf4d..c82c057dd 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazApi.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazApi.cs @@ -46,6 +46,11 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz public List Data { get; set; } } + public class AvistazErrorResponse + { + public string Message { get; set; } + } + public class AvistazIdInfo { public string Tmdb { get; set; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs index 3663f1250..f0158aef4 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazBase.cs @@ -89,6 +89,22 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz { await GetToken(); } + catch (HttpException ex) + { + if (ex.Response.StatusCode == HttpStatusCode.Unauthorized) + { + _logger.Warn(ex, "Unauthorized request to indexer"); + + var jsonResponse = new HttpResponse(ex.Response); + return new ValidationFailure(string.Empty, jsonResponse.Resource?.Message ?? "Unauthorized request to indexer"); + } + else + { + _logger.Warn(ex, "Unable to connect to indexer"); + + return new ValidationFailure(string.Empty, "Unable to connect to indexer, check the log for more details"); + } + } catch (Exception ex) { _logger.Warn(ex, "Unable to connect to indexer");