From d651e6ac52095f1d36219b7b54e6c0ef70d658ae Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 15 Dec 2014 20:46:55 -0800 Subject: [PATCH] Prevent invalid response to get torrents from Deluge from throwing an error --- .../Download/Clients/Deluge/DelugeProxy.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs index d64a99b4e..970af4939 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs @@ -66,7 +66,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge //var response = ProcessRequest>(settings, "core.get_torrents_status", filter, new String[0]); var response = ProcessRequest(settings, "web.update_ui", requiredProperties, filter); - return response.Result.Torrents.Values.ToArray(); + return GetTorrents(response.Result); } public DelugeTorrent[] GetTorrentsByLabel(String label, DelugeSettings settings) @@ -74,11 +74,10 @@ namespace NzbDrone.Core.Download.Clients.Deluge var filter = new Dictionary(); filter.Add("label", label); - //var response = ProcessRequest>(settings, "core.get_torrents_status", filter, new String[0]); var response = ProcessRequest(settings, "web.update_ui", requiredProperties, filter); - return response.Result.Torrents.Values.ToArray(); + return GetTorrents(response.Result); } public String AddTorrentFromMagnet(String magnetLink, DelugeSettings settings) @@ -301,5 +300,15 @@ namespace NzbDrone.Core.Download.Clients.Deluge { return System.Threading.Interlocked.Increment(ref _callId); } + + private DelugeTorrent[] GetTorrents(DelugeUpdateUIResult result) + { + if (result.Torrents == null) + { + return new DelugeTorrent[0]; + } + + return result.Torrents.Values.ToArray(); + } } }