Handle add to queue errors in SAB
This commit is contained in:
parent
5cc2810f77
commit
96a14bab9a
|
@ -4,6 +4,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
@ -208,5 +209,15 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().Be("0.6.9");
|
result.Should().Be("0.6.9");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_false_when_WebException_is_thrown()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<HttpProvider>()
|
||||||
|
.Setup(s => s.DownloadString(It.IsAny<String>())).Throws(new WebException());
|
||||||
|
|
||||||
|
Mocker.Resolve<SabProvider>().DownloadNzb(url, title).Should().BeFalse();
|
||||||
|
ExceptionVerification.ExpectedErrors(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
@ -79,30 +80,38 @@ namespace NzbDrone.Core.Providers.DownloadClients
|
||||||
|
|
||||||
public virtual bool DownloadNzb(string url, string title)
|
public virtual bool DownloadNzb(string url, string title)
|
||||||
{
|
{
|
||||||
string cat = _configProvider.SabTvCategory;
|
try
|
||||||
int priority = (int)_configProvider.SabTvPriority;
|
|
||||||
string name = GetNzbName(url);
|
|
||||||
string nzbName = HttpUtility.UrlEncode(title);
|
|
||||||
|
|
||||||
string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}",
|
|
||||||
name, priority, cat, nzbName);
|
|
||||||
|
|
||||||
if (url.ToLower().Contains("newzbin"))
|
|
||||||
{
|
{
|
||||||
action = action.Replace("mode=addurl", "mode=addid");
|
string cat = _configProvider.SabTvCategory;
|
||||||
|
int priority = (int)_configProvider.SabTvPriority;
|
||||||
|
string name = GetNzbName(url);
|
||||||
|
string nzbName = HttpUtility.UrlEncode(title);
|
||||||
|
|
||||||
|
string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}",
|
||||||
|
name, priority, cat, nzbName);
|
||||||
|
|
||||||
|
if (url.ToLower().Contains("newzbin"))
|
||||||
|
{
|
||||||
|
action = action.Replace("mode=addurl", "mode=addid");
|
||||||
|
}
|
||||||
|
|
||||||
|
string request = GetSabRequest(action);
|
||||||
|
logger.Info("Adding report [{0}] to the queue.", title);
|
||||||
|
|
||||||
|
var response = _httpProvider.DownloadString(request).Replace("\n", String.Empty);
|
||||||
|
|
||||||
|
logger.Debug("Queue Response: [{0}]", response);
|
||||||
|
|
||||||
|
if (response == "ok")
|
||||||
|
return true;
|
||||||
|
|
||||||
|
logger.Warn("SAB returned unexpected response '{0}'", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
string request = GetSabRequest(action);
|
catch (WebException ex)
|
||||||
|
{
|
||||||
logger.Info("Adding report [{0}] to the queue.", title);
|
logger.Error("Error communicating with SAB");
|
||||||
|
}
|
||||||
string response = _httpProvider.DownloadString(request).Replace("\n", String.Empty);
|
|
||||||
logger.Debug("Queue Response: [{0}]", response);
|
|
||||||
|
|
||||||
if (response == "ok")
|
|
||||||
return true;
|
|
||||||
|
|
||||||
logger.Warn("SAB returned unexpected response '{0}'", response);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue