From 1154e0eeb3a61f04794464136c534facd1ab817b Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 17 Mar 2016 20:53:11 +0100 Subject: [PATCH] Add WebException handlers to prevent them reaching the UI. --- .../Download/Clients/Deluge/DelugeProxy.cs | 4 ++++ .../Download/Clients/NzbVortex/NzbVortexProxy.cs | 5 +++++ .../Download/Clients/Nzbget/NzbgetProxy.cs | 4 ++++ .../Download/Clients/Sabnzbd/SabnzbdProxy.cs | 5 +++++ .../Download/Clients/qBittorrent/QBittorrentProxy.cs | 12 ++++++++++-- .../Download/Clients/uTorrent/UTorrentProxy.cs | 10 +++++++++- 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs index c64f55c3e..52e98224f 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs @@ -229,6 +229,10 @@ private JsonRpcResponse ProcessRequest(JsonRpcRequestBuilder r throw new DownloadClientException("Unable to connect to Deluge, please check your settings", ex); } } + catch (WebException ex) + { + throw new DownloadClientException("Unable to connect to Deluge, please check your settings", ex); + } } private void AuthenticateClient(JsonRpcRequestBuilder requestBuilder, DelugeSettings settings, bool reauthenticate = false) diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexProxy.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexProxy.cs index 45898c2d3..f599032c1 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/NzbVortexProxy.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net; using Newtonsoft.Json; using NLog; using NzbDrone.Common.Cache; @@ -158,6 +159,10 @@ private T ProcessRequest(HttpRequestBuilder requestBuilder, bool requiresAuth { throw new DownloadClientException("Unable to connect to NZBVortex, please check your settings", ex); } + catch (WebException ex) + { + throw new DownloadClientException("Unable to connect to NZBVortex, please check your settings", ex); + } } private void AuthenticateClient(HttpRequestBuilder requestBuilder, NzbVortexSettings settings, bool reauthenticate = false) diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs index 3fa1d521b..b333a890b 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs @@ -174,6 +174,10 @@ private T ProcessRequest(NzbgetSettings settings, string method, params objec throw new DownloadClientException("Unable to connect to NzbGet. " + ex.Message, ex); } + catch (WebException ex) + { + throw new DownloadClientException("Unable to connect to NzbGet. " + ex.Message, ex); + } _logger.Trace("Response: {0}", response.Content); diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs index ec6cb123d..499129d13 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs @@ -5,6 +5,7 @@ using NzbDrone.Common.Serializer; using NzbDrone.Core.Download.Clients.Sabnzbd.Responses; using NzbDrone.Common.Http; +using System.Net; namespace NzbDrone.Core.Download.Clients.Sabnzbd { @@ -167,6 +168,10 @@ private string ProcessRequest(HttpRequestBuilder requestBuilder, SabnzbdSettings { throw new DownloadClientException("Unable to connect to SABnzbd, please check your settings", ex); } + catch (WebException ex) + { + throw new DownloadClientException("Unable to connect to SABnzbd, please check your settings", ex); + } _logger.Trace("Response: {0}", response.Content); diff --git a/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs b/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs index 2e4d2df4a..2b92d4913 100644 --- a/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs @@ -160,9 +160,13 @@ private TResult ProcessRequest(HttpRequestBuilder requestBuilder, QBitt } else { - throw new DownloadClientException("Failed to connect to download client", ex); + throw new DownloadClientException("Failed to connect to qBitTorrent, check your settings.", ex); } } + catch (WebException ex) + { + throw new DownloadClientException("Failed to connect to qBitTorrent, please check your settings.", ex); + } return Json.Deserialize(response.Content); } @@ -201,7 +205,11 @@ private void AuthenticateClient(HttpRequestBuilder requestBuilder, QBittorrentSe throw new DownloadClientAuthenticationException("Failed to authenticate with qbitTorrent.", ex); } - throw; + throw new DownloadClientException("Failed to connect to qBitTorrent, please check your settings.", ex); + } + catch (WebException ex) + { + throw new DownloadClientException("Failed to connect to qBitTorrent, please check your settings.", ex); } if (response.Content != "Ok.") // returns "Fails." on bad login diff --git a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs index ed759e8cf..41d46c531 100644 --- a/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/uTorrent/UTorrentProxy.cs @@ -193,6 +193,10 @@ public UTorrentResponse ProcessRequest(HttpRequestBuilder requestBuilder, UTorre throw new DownloadClientException("Unable to connect to Deluge, please check your settings", ex); } } + catch (WebException ex) + { + throw new DownloadClientException("Unable to connect to Deluge, please check your settings", ex); + } return Json.Deserialize(response.Content); } @@ -230,7 +234,11 @@ private void AuthenticateClient(HttpRequestBuilder requestBuilder, UTorrentSetti throw new DownloadClientAuthenticationException("Failed to authenticate with uTorrent."); } - throw; + throw new DownloadClientException("Unable to connect to uTorrent, please check your settings", ex); + } + catch (WebException ex) + { + throw new DownloadClientException("Unable to connect to uTorrent, please check your settings", ex); } cookies = response.GetCookies();