From 65d6d518d78e45dcd9257536a93fe9ef4e0d069b Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Tue, 18 Apr 2023 19:44:22 -0500 Subject: [PATCH] New: Improve applications error reporting for requests (#1618) Co-authored-by: Bogdan --- .../Applications/Lidarr/LidarrV1Proxy.cs | 69 ++++++++++++++++--- .../Applications/Radarr/RadarrV3Proxy.cs | 69 ++++++++++++++++--- .../Applications/Readarr/ReadarrV1Proxy.cs | 69 ++++++++++++++++--- .../Applications/Sonarr/SonarrV3Proxy.cs | 69 ++++++++++++++++--- .../Applications/Whisparr/WhisparrV3Proxy.cs | 67 +++++++++++++++--- 5 files changed, 294 insertions(+), 49 deletions(-) diff --git a/src/NzbDrone.Core/Applications/Lidarr/LidarrV1Proxy.cs b/src/NzbDrone.Core/Applications/Lidarr/LidarrV1Proxy.cs index e46c603ea..0ddb25e55 100644 --- a/src/NzbDrone.Core/Applications/Lidarr/LidarrV1Proxy.cs +++ b/src/NzbDrone.Core/Applications/Lidarr/LidarrV1Proxy.cs @@ -23,6 +23,8 @@ namespace NzbDrone.Core.Applications.Lidarr public class LidarrV1Proxy : ILidarrV1Proxy { + private const string AppApiRoute = "/api/v1"; + private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer"; private readonly IHttpClient _httpClient; private readonly Logger _logger; @@ -34,13 +36,13 @@ namespace NzbDrone.Core.Applications.Lidarr public LidarrStatus GetStatus(LidarrSettings settings) { - var request = BuildRequest(settings, "/api/v1/system/status", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppApiRoute}/system/status", HttpMethod.Get); return Execute(request); } public List GetIndexers(LidarrSettings settings) { - var request = BuildRequest(settings, "/api/v1/indexer", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Get); return Execute>(request); } @@ -48,7 +50,7 @@ namespace NzbDrone.Core.Applications.Lidarr { try { - var request = BuildRequest(settings, $"/api/v1/indexer/{indexerId}", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Get); return Execute(request); } catch (HttpException ex) @@ -64,37 +66,37 @@ namespace NzbDrone.Core.Applications.Lidarr public void RemoveIndexer(int indexerId, LidarrSettings settings) { - var request = BuildRequest(settings, $"/api/v1/indexer/{indexerId}", HttpMethod.Delete); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Delete); _httpClient.Execute(request); } public List GetIndexerSchema(LidarrSettings settings) { - var request = BuildRequest(settings, "/api/v1/indexer/schema", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/schema", HttpMethod.Get); return Execute>(request); } public LidarrIndexer AddIndexer(LidarrIndexer indexer, LidarrSettings settings) { - var request = BuildRequest(settings, "/api/v1/indexer", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Post); request.SetContent(indexer.ToJson()); - return Execute(request); + return ExecuteIndexerRequest(request); } public LidarrIndexer UpdateIndexer(LidarrIndexer indexer, LidarrSettings settings) { - var request = BuildRequest(settings, $"/api/v1/indexer/{indexer.Id}", HttpMethod.Put); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexer.Id}", HttpMethod.Put); request.SetContent(indexer.ToJson()); - return Execute(request); + return ExecuteIndexerRequest(request); } public ValidationFailure TestConnection(LidarrIndexer indexer, LidarrSettings settings) { - var request = BuildRequest(settings, $"/api/v1/indexer/test", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/test", HttpMethod.Post); request.SetContent(indexer.ToJson()); @@ -134,6 +136,53 @@ namespace NzbDrone.Core.Applications.Lidarr return null; } + private LidarrIndexer ExecuteIndexerRequest(HttpRequest request) + { + try + { + return Execute(request); + } + catch (HttpException ex) + { + switch (ex.Response.StatusCode) + { + case HttpStatusCode.Unauthorized: + _logger.Error(ex, "API Key is invalid"); + break; + case HttpStatusCode.BadRequest: + if (ex.Response.Content.Contains("Query successful, but no results in the configured categories were returned from your indexer.", StringComparison.InvariantCultureIgnoreCase)) + { + _logger.Error(ex, "No Results in configured categories. See FAQ Entry: Prowlarr will not sync X Indexer to App"); + break; + } + + _logger.Error(ex, "Invalid Request"); + break; + case HttpStatusCode.SeeOther: + _logger.Error(ex, "App returned redirect and is invalid. Check App URL"); + break; + case HttpStatusCode.NotFound: + _logger.Error(ex, "Remote indexer not found"); + break; + default: + _logger.Error(ex, "Unexpected response status code: {0}", ex.Response.StatusCode); + throw; + } + } + catch (JsonReaderException ex) + { + _logger.Error(ex, "Unable to parse JSON response from application"); + throw; + } + catch (Exception ex) + { + _logger.Error(ex, "Unable to add or update indexer"); + throw; + } + + return null; + } + private HttpRequest BuildRequest(LidarrSettings settings, string resource, HttpMethod method) { var baseUrl = settings.BaseUrl.TrimEnd('/'); diff --git a/src/NzbDrone.Core/Applications/Radarr/RadarrV3Proxy.cs b/src/NzbDrone.Core/Applications/Radarr/RadarrV3Proxy.cs index c5445c7d0..6e4efa1a1 100644 --- a/src/NzbDrone.Core/Applications/Radarr/RadarrV3Proxy.cs +++ b/src/NzbDrone.Core/Applications/Radarr/RadarrV3Proxy.cs @@ -23,6 +23,8 @@ namespace NzbDrone.Core.Applications.Radarr public class RadarrV3Proxy : IRadarrV3Proxy { + private const string AppApiRoute = "/api/v3"; + private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer"; private readonly IHttpClient _httpClient; private readonly Logger _logger; @@ -34,13 +36,13 @@ namespace NzbDrone.Core.Applications.Radarr public RadarrStatus GetStatus(RadarrSettings settings) { - var request = BuildRequest(settings, "/api/v3/system/status", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppApiRoute}/system/status", HttpMethod.Get); return Execute(request); } public List GetIndexers(RadarrSettings settings) { - var request = BuildRequest(settings, "/api/v3/indexer", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Get); return Execute>(request); } @@ -48,7 +50,7 @@ namespace NzbDrone.Core.Applications.Radarr { try { - var request = BuildRequest(settings, $"/api/v3/indexer/{indexerId}", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Get); return Execute(request); } catch (HttpException ex) @@ -64,37 +66,37 @@ namespace NzbDrone.Core.Applications.Radarr public void RemoveIndexer(int indexerId, RadarrSettings settings) { - var request = BuildRequest(settings, $"/api/v3/indexer/{indexerId}", HttpMethod.Delete); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Delete); _httpClient.Execute(request); } public List GetIndexerSchema(RadarrSettings settings) { - var request = BuildRequest(settings, "/api/v3/indexer/schema", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/schema", HttpMethod.Get); return Execute>(request); } public RadarrIndexer AddIndexer(RadarrIndexer indexer, RadarrSettings settings) { - var request = BuildRequest(settings, "/api/v3/indexer", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Post); request.SetContent(indexer.ToJson()); - return Execute(request); + return ExecuteIndexerRequest(request); } public RadarrIndexer UpdateIndexer(RadarrIndexer indexer, RadarrSettings settings) { - var request = BuildRequest(settings, $"/api/v3/indexer/{indexer.Id}", HttpMethod.Put); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexer.Id}", HttpMethod.Put); request.SetContent(indexer.ToJson()); - return Execute(request); + return ExecuteIndexerRequest(request); } public ValidationFailure TestConnection(RadarrIndexer indexer, RadarrSettings settings) { - var request = BuildRequest(settings, $"/api/v3/indexer/test", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/test", HttpMethod.Post); request.SetContent(indexer.ToJson()); @@ -134,6 +136,53 @@ namespace NzbDrone.Core.Applications.Radarr return null; } + private RadarrIndexer ExecuteIndexerRequest(HttpRequest request) + { + try + { + return Execute(request); + } + catch (HttpException ex) + { + switch (ex.Response.StatusCode) + { + case HttpStatusCode.Unauthorized: + _logger.Error(ex, "API Key is invalid"); + break; + case HttpStatusCode.BadRequest: + if (ex.Response.Content.Contains("Query successful, but no results in the configured categories were returned from your indexer.", StringComparison.InvariantCultureIgnoreCase)) + { + _logger.Error(ex, "No Results in configured categories. See FAQ Entry: Prowlarr will not sync X Indexer to App"); + break; + } + + _logger.Error(ex, "Invalid Request"); + break; + case HttpStatusCode.SeeOther: + _logger.Error(ex, "App returned redirect and is invalid. Check App URL"); + break; + case HttpStatusCode.NotFound: + _logger.Error(ex, "Remote indexer not found"); + break; + default: + _logger.Error(ex, "Unexpected response status code: {0}", ex.Response.StatusCode); + throw; + } + } + catch (JsonReaderException ex) + { + _logger.Error(ex, "Unable to parse JSON response from application"); + throw; + } + catch (Exception ex) + { + _logger.Error(ex, "Unable to add or update indexer"); + throw; + } + + return null; + } + private HttpRequest BuildRequest(RadarrSettings settings, string resource, HttpMethod method) { var baseUrl = settings.BaseUrl.TrimEnd('/'); diff --git a/src/NzbDrone.Core/Applications/Readarr/ReadarrV1Proxy.cs b/src/NzbDrone.Core/Applications/Readarr/ReadarrV1Proxy.cs index 0a5319a47..3d74a517b 100644 --- a/src/NzbDrone.Core/Applications/Readarr/ReadarrV1Proxy.cs +++ b/src/NzbDrone.Core/Applications/Readarr/ReadarrV1Proxy.cs @@ -23,6 +23,8 @@ namespace NzbDrone.Core.Applications.Readarr public class ReadarrV1Proxy : IReadarrV1Proxy { + private const string AppApiRoute = "/api/v1"; + private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer"; private readonly IHttpClient _httpClient; private readonly Logger _logger; @@ -34,13 +36,13 @@ namespace NzbDrone.Core.Applications.Readarr public ReadarrStatus GetStatus(ReadarrSettings settings) { - var request = BuildRequest(settings, "/api/v1/system/status", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppApiRoute}/system/status", HttpMethod.Get); return Execute(request); } public List GetIndexers(ReadarrSettings settings) { - var request = BuildRequest(settings, "/api/v1/indexer", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Get); return Execute>(request); } @@ -48,7 +50,7 @@ namespace NzbDrone.Core.Applications.Readarr { try { - var request = BuildRequest(settings, $"/api/v1/indexer/{indexerId}", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Get); return Execute(request); } catch (HttpException ex) @@ -64,37 +66,37 @@ namespace NzbDrone.Core.Applications.Readarr public void RemoveIndexer(int indexerId, ReadarrSettings settings) { - var request = BuildRequest(settings, $"/api/v1/indexer/{indexerId}", HttpMethod.Delete); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Delete); _httpClient.Execute(request); } public List GetIndexerSchema(ReadarrSettings settings) { - var request = BuildRequest(settings, "/api/v1/indexer/schema", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/schema", HttpMethod.Get); return Execute>(request); } public ReadarrIndexer AddIndexer(ReadarrIndexer indexer, ReadarrSettings settings) { - var request = BuildRequest(settings, "/api/v1/indexer", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Post); request.SetContent(indexer.ToJson()); - return Execute(request); + return ExecuteIndexerRequest(request); } public ReadarrIndexer UpdateIndexer(ReadarrIndexer indexer, ReadarrSettings settings) { - var request = BuildRequest(settings, $"/api/v1/indexer/{indexer.Id}", HttpMethod.Put); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexer.Id}", HttpMethod.Put); request.SetContent(indexer.ToJson()); - return Execute(request); + return ExecuteIndexerRequest(request); } public ValidationFailure TestConnection(ReadarrIndexer indexer, ReadarrSettings settings) { - var request = BuildRequest(settings, $"/api/v1/indexer/test", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/test", HttpMethod.Post); request.SetContent(indexer.ToJson()); @@ -134,6 +136,53 @@ namespace NzbDrone.Core.Applications.Readarr return null; } + private ReadarrIndexer ExecuteIndexerRequest(HttpRequest request) + { + try + { + return Execute(request); + } + catch (HttpException ex) + { + switch (ex.Response.StatusCode) + { + case HttpStatusCode.Unauthorized: + _logger.Error(ex, "API Key is invalid"); + break; + case HttpStatusCode.BadRequest: + if (ex.Response.Content.Contains("Query successful, but no results in the configured categories were returned from your indexer.", StringComparison.InvariantCultureIgnoreCase)) + { + _logger.Error(ex, "No Results in configured categories. See FAQ Entry: Prowlarr will not sync X Indexer to App"); + break; + } + + _logger.Error(ex, "Invalid Request"); + break; + case HttpStatusCode.SeeOther: + _logger.Error(ex, "App returned redirect and is invalid. Check App URL"); + break; + case HttpStatusCode.NotFound: + _logger.Error(ex, "Remote indexer not found"); + break; + default: + _logger.Error(ex, "Unexpected response status code: {0}", ex.Response.StatusCode); + throw; + } + } + catch (JsonReaderException ex) + { + _logger.Error(ex, "Unable to parse JSON response from application"); + throw; + } + catch (Exception ex) + { + _logger.Error(ex, "Unable to add or update indexer"); + throw; + } + + return null; + } + private HttpRequest BuildRequest(ReadarrSettings settings, string resource, HttpMethod method) { var baseUrl = settings.BaseUrl.TrimEnd('/'); diff --git a/src/NzbDrone.Core/Applications/Sonarr/SonarrV3Proxy.cs b/src/NzbDrone.Core/Applications/Sonarr/SonarrV3Proxy.cs index 9e8436f56..018338386 100644 --- a/src/NzbDrone.Core/Applications/Sonarr/SonarrV3Proxy.cs +++ b/src/NzbDrone.Core/Applications/Sonarr/SonarrV3Proxy.cs @@ -23,6 +23,8 @@ namespace NzbDrone.Core.Applications.Sonarr public class SonarrV3Proxy : ISonarrV3Proxy { + private const string AppApiRoute = "/api/v3"; + private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer"; private readonly IHttpClient _httpClient; private readonly Logger _logger; @@ -34,13 +36,13 @@ namespace NzbDrone.Core.Applications.Sonarr public SonarrStatus GetStatus(SonarrSettings settings) { - var request = BuildRequest(settings, "/api/v3/system/status", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppApiRoute}/system/status", HttpMethod.Get); return Execute(request); } public List GetIndexers(SonarrSettings settings) { - var request = BuildRequest(settings, "/api/v3/indexer", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Get); return Execute>(request); } @@ -48,7 +50,7 @@ namespace NzbDrone.Core.Applications.Sonarr { try { - var request = BuildRequest(settings, $"/api/v3/indexer/{indexerId}", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Get); return Execute(request); } catch (HttpException ex) @@ -64,37 +66,37 @@ namespace NzbDrone.Core.Applications.Sonarr public void RemoveIndexer(int indexerId, SonarrSettings settings) { - var request = BuildRequest(settings, $"/api/v3/indexer/{indexerId}", HttpMethod.Delete); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Delete); _httpClient.Execute(request); } public List GetIndexerSchema(SonarrSettings settings) { - var request = BuildRequest(settings, "/api/v3/indexer/schema", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/schema", HttpMethod.Get); return Execute>(request); } public SonarrIndexer AddIndexer(SonarrIndexer indexer, SonarrSettings settings) { - var request = BuildRequest(settings, "/api/v3/indexer", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Post); request.SetContent(indexer.ToJson()); - return Execute(request); + return ExecuteIndexerRequest(request); } public SonarrIndexer UpdateIndexer(SonarrIndexer indexer, SonarrSettings settings) { - var request = BuildRequest(settings, $"/api/v3/indexer/{indexer.Id}", HttpMethod.Put); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexer.Id}", HttpMethod.Put); request.SetContent(indexer.ToJson()); - return Execute(request); + return ExecuteIndexerRequest(request); } public ValidationFailure TestConnection(SonarrIndexer indexer, SonarrSettings settings) { - var request = BuildRequest(settings, $"/api/v3/indexer/test", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/test", HttpMethod.Post); request.SetContent(indexer.ToJson()); @@ -140,6 +142,53 @@ namespace NzbDrone.Core.Applications.Sonarr return null; } + private SonarrIndexer ExecuteIndexerRequest(HttpRequest request) + { + try + { + return Execute(request); + } + catch (HttpException ex) + { + switch (ex.Response.StatusCode) + { + case HttpStatusCode.Unauthorized: + _logger.Error(ex, "API Key is invalid"); + break; + case HttpStatusCode.BadRequest: + if (ex.Response.Content.Contains("Query successful, but no results in the configured categories were returned from your indexer.", StringComparison.InvariantCultureIgnoreCase)) + { + _logger.Error(ex, "No Results in configured categories. See FAQ Entry: Prowlarr will not sync X Indexer to App"); + break; + } + + _logger.Error(ex, "Invalid Request"); + break; + case HttpStatusCode.SeeOther: + _logger.Error(ex, "App returned redirect and is invalid. Check App URL"); + break; + case HttpStatusCode.NotFound: + _logger.Error(ex, "Remote indexer not found"); + break; + default: + _logger.Error(ex, "Unexpected response status code: {0}", ex.Response.StatusCode); + throw; + } + } + catch (JsonReaderException ex) + { + _logger.Error(ex, "Unable to parse JSON response from application"); + throw; + } + catch (Exception ex) + { + _logger.Error(ex, "Unable to add or update indexer"); + throw; + } + + return null; + } + private HttpRequest BuildRequest(SonarrSettings settings, string resource, HttpMethod method) { var baseUrl = settings.BaseUrl.TrimEnd('/'); diff --git a/src/NzbDrone.Core/Applications/Whisparr/WhisparrV3Proxy.cs b/src/NzbDrone.Core/Applications/Whisparr/WhisparrV3Proxy.cs index bb3d01616..4a80cbed5 100644 --- a/src/NzbDrone.Core/Applications/Whisparr/WhisparrV3Proxy.cs +++ b/src/NzbDrone.Core/Applications/Whisparr/WhisparrV3Proxy.cs @@ -23,6 +23,8 @@ namespace NzbDrone.Core.Applications.Whisparr public class WhisparrV3Proxy : IWhisparrV3Proxy { + private const string AppApiRoute = "/api/v3"; + private const string AppIndexerApiRoute = $"{AppApiRoute}/indexer"; private readonly IHttpClient _httpClient; private readonly Logger _logger; @@ -34,13 +36,13 @@ namespace NzbDrone.Core.Applications.Whisparr public WhisparrStatus GetStatus(WhisparrSettings settings) { - var request = BuildRequest(settings, "/api/v3/system/status", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppApiRoute}/system/status", HttpMethod.Get); return Execute(request); } public List GetIndexers(WhisparrSettings settings) { - var request = BuildRequest(settings, "/api/v3/indexer", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Get); return Execute>(request); } @@ -48,7 +50,7 @@ namespace NzbDrone.Core.Applications.Whisparr { try { - var request = BuildRequest(settings, $"/api/v3/indexer/{indexerId}", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Get); return Execute(request); } catch (HttpException ex) @@ -64,19 +66,19 @@ namespace NzbDrone.Core.Applications.Whisparr public void RemoveIndexer(int indexerId, WhisparrSettings settings) { - var request = BuildRequest(settings, $"/api/v3/indexer/{indexerId}", HttpMethod.Delete); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexerId}", HttpMethod.Delete); _httpClient.Execute(request); } public List GetIndexerSchema(WhisparrSettings settings) { - var request = BuildRequest(settings, "/api/v3/indexer/schema", HttpMethod.Get); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/schema", HttpMethod.Get); return Execute>(request); } public WhisparrIndexer AddIndexer(WhisparrIndexer indexer, WhisparrSettings settings) { - var request = BuildRequest(settings, "/api/v3/indexer", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}", HttpMethod.Post); request.SetContent(indexer.ToJson()); @@ -85,16 +87,16 @@ namespace NzbDrone.Core.Applications.Whisparr public WhisparrIndexer UpdateIndexer(WhisparrIndexer indexer, WhisparrSettings settings) { - var request = BuildRequest(settings, $"/api/v3/indexer/{indexer.Id}", HttpMethod.Put); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/{indexer.Id}", HttpMethod.Put); request.SetContent(indexer.ToJson()); - return Execute(request); + return ExecuteIndexerRequest(request); } public ValidationFailure TestConnection(WhisparrIndexer indexer, WhisparrSettings settings) { - var request = BuildRequest(settings, $"/api/v3/indexer/test", HttpMethod.Post); + var request = BuildRequest(settings, $"{AppIndexerApiRoute}/test", HttpMethod.Post); request.SetContent(indexer.ToJson()); @@ -134,6 +136,53 @@ namespace NzbDrone.Core.Applications.Whisparr return null; } + private WhisparrIndexer ExecuteIndexerRequest(HttpRequest request) + { + try + { + return Execute(request); + } + catch (HttpException ex) + { + switch (ex.Response.StatusCode) + { + case HttpStatusCode.Unauthorized: + _logger.Error(ex, "API Key is invalid"); + break; + case HttpStatusCode.BadRequest: + if (ex.Response.Content.Contains("Query successful, but no results in the configured categories were returned from your indexer.", StringComparison.InvariantCultureIgnoreCase)) + { + _logger.Error(ex, "No Results in configured categories. See FAQ Entry: Prowlarr will not sync X Indexer to App"); + break; + } + + _logger.Error(ex, "Invalid Request"); + break; + case HttpStatusCode.SeeOther: + _logger.Error(ex, "App returned redirect and is invalid. Check App URL"); + break; + case HttpStatusCode.NotFound: + _logger.Error(ex, "Remote indexer not found"); + break; + default: + _logger.Error(ex, "Unexpected response status code: {0}", ex.Response.StatusCode); + throw; + } + } + catch (JsonReaderException ex) + { + _logger.Error(ex, "Unable to parse JSON response from application"); + throw; + } + catch (Exception ex) + { + _logger.Error(ex, "Unable to add or update indexer"); + throw; + } + + return null; + } + private HttpRequest BuildRequest(WhisparrSettings settings, string resource, HttpMethod method) { var baseUrl = settings.BaseUrl.TrimEnd('/');