Improved error message when nzb download contains an newznab error instead
This commit is contained in:
parent
d369d85699
commit
776191b3bd
|
@ -11,5 +11,21 @@ namespace NzbDrone.Common.Extensions
|
||||||
{
|
{
|
||||||
return container.Descendants().Where(c => c.Name.LocalName.Equals(localName, StringComparison.InvariantCultureIgnoreCase));
|
return container.Descendants().Where(c => c.Name.LocalName.Equals(localName, StringComparison.InvariantCultureIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool TryGetAttributeValue(this XElement element, string name, out string value)
|
||||||
|
{
|
||||||
|
var attr = element.Attribute(name);
|
||||||
|
|
||||||
|
if (attr != null)
|
||||||
|
{
|
||||||
|
value = attr.Value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Download;
|
using NzbDrone.Core.Download;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
@ -31,6 +32,17 @@ namespace NzbDrone.Core.Test.Download
|
||||||
Assert.Throws<InvalidNzbException>(() => Subject.Validate(filename, fileContent));
|
Assert.Throws<InvalidNzbException>(() => Subject.Validate(filename, fileContent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_throw_on_newznab_error()
|
||||||
|
{
|
||||||
|
var filename = "NewznabError";
|
||||||
|
var fileContent = GivenNzbFile(filename);
|
||||||
|
|
||||||
|
var ex = Assert.Throws<InvalidNzbException>(() => Subject.Validate(filename, fileContent));
|
||||||
|
|
||||||
|
ex.Message.Should().Contain("201 - Incorrect parameter");
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_validate_nzb()
|
public void should_validate_nzb()
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<error code="201" description="Incorrect parameter" />
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
@ -27,6 +28,14 @@ namespace NzbDrone.Core.Download
|
||||||
throw new InvalidNzbException("Invalid NZB: No Root element [{0}]", filename);
|
throw new InvalidNzbException("Invalid NZB: No Root element [{0}]", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nZEDb has an bug in their error reporting code spitting out invalid http status codes
|
||||||
|
if (nzb.Name.LocalName.Equals("error") &&
|
||||||
|
nzb.TryGetAttributeValue("code", out var code) &&
|
||||||
|
nzb.TryGetAttributeValue("description", out var description))
|
||||||
|
{
|
||||||
|
throw new InvalidNzbException("Invalid NZB: Contains indexer error: {0} - {1}", code, description);
|
||||||
|
}
|
||||||
|
|
||||||
if (!nzb.Name.LocalName.Equals("nzb"))
|
if (!nzb.Name.LocalName.Equals("nzb"))
|
||||||
{
|
{
|
||||||
throw new InvalidNzbException("Invalid NZB: Unexpected root element. Expected 'nzb' found '{0}' [{1}]", nzb.Name.LocalName, filename);
|
throw new InvalidNzbException("Invalid NZB: Unexpected root element. Expected 'nzb' found '{0}' [{1}]", nzb.Name.LocalName, filename);
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace NzbDrone.Core.Download
|
||||||
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
|
if (ex.Response.StatusCode == HttpStatusCode.NotFound)
|
||||||
{
|
{
|
||||||
_logger.Error(ex, "Downloading nzb file for episode '{0}' failed since it no longer exists ({1})", remoteEpisode.Release.Title, url);
|
_logger.Error(ex, "Downloading nzb file for episode '{0}' failed since it no longer exists ({1})", remoteEpisode.Release.Title, url);
|
||||||
throw new ReleaseUnavailableException(remoteEpisode.Release, "Downloading torrent failed", ex);
|
throw new ReleaseUnavailableException(remoteEpisode.Release, "Downloading nzb failed", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((int)ex.Response.StatusCode == 429)
|
if ((int)ex.Response.StatusCode == 429)
|
||||||
|
|
Loading…
Reference in New Issue