mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Updated test logic to report exceptions gracefully.
This commit is contained in:
parent
25abeb8c9c
commit
f9586e6f77
@ -1,14 +1,30 @@
|
|||||||
using NzbDrone.Common.Exceptions;
|
using System;
|
||||||
|
using NzbDrone.Common.Exceptions;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download.Clients
|
namespace NzbDrone.Core.Download.Clients
|
||||||
{
|
{
|
||||||
public class DownloadClientException : NzbDroneException
|
public class DownloadClientException : NzbDroneException
|
||||||
{
|
{
|
||||||
public DownloadClientException(string message, params object[] args) : base(message, args)
|
public DownloadClientException(string message, params object[] args)
|
||||||
|
: base(string.Format(message, args))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadClientException(string message) : base(message)
|
public DownloadClientException(string message)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DownloadClientException(string message, Exception innerException, params object[] args)
|
||||||
|
: base(string.Format(message, args), innerException)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DownloadClientException(string message, Exception innerException)
|
||||||
|
: base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
using NzbDrone.Core.Parser;
|
using NzbDrone.Core.Parser;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Validation;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download.Clients.Nzbget
|
namespace NzbDrone.Core.Download.Clients.Nzbget
|
||||||
{
|
{
|
||||||
@ -290,10 +291,8 @@ protected IEnumerable<NzbgetCategory> GetCategories(Dictionary<String, String> c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ValidationResult Test()
|
protected override void Test(List<ValidationFailure> failures)
|
||||||
{
|
{
|
||||||
var failures = new List<ValidationFailure>();
|
|
||||||
|
|
||||||
failures.AddIfNotNull(TestConnection());
|
failures.AddIfNotNull(TestConnection());
|
||||||
failures.AddIfNotNull(TestCategory());
|
failures.AddIfNotNull(TestCategory());
|
||||||
|
|
||||||
@ -301,8 +300,6 @@ public override ValidationResult Test()
|
|||||||
{
|
{
|
||||||
failures.AddIfNotNull(TestFolder(Settings.TvCategoryLocalPath, "TvCategoryLocalPath"));
|
failures.AddIfNotNull(TestFolder(Settings.TvCategoryLocalPath, "TvCategoryLocalPath"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ValidationResult(failures);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValidationFailure TestConnection()
|
private ValidationFailure TestConnection()
|
||||||
@ -313,6 +310,10 @@ private ValidationFailure TestConnection()
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
if (ex.Message.ContainsIgnoreCase("Authentication failed"))
|
||||||
|
{
|
||||||
|
return new ValidationFailure("Username", "Authentication failed");
|
||||||
|
}
|
||||||
_logger.ErrorException(ex.Message, ex);
|
_logger.ErrorException(ex.Message, ex);
|
||||||
return new ValidationFailure("Host", "Unable to connect to NZBGet");
|
return new ValidationFailure("Host", "Unable to connect to NZBGet");
|
||||||
}
|
}
|
||||||
@ -327,7 +328,11 @@ private ValidationFailure TestCategory()
|
|||||||
|
|
||||||
if (!Settings.TvCategory.IsNullOrWhiteSpace() && !categories.Any(v => v.Name == Settings.TvCategory))
|
if (!Settings.TvCategory.IsNullOrWhiteSpace() && !categories.Any(v => v.Name == Settings.TvCategory))
|
||||||
{
|
{
|
||||||
return new ValidationFailure("TvCategory", "Category does not exist");
|
return new NzbDroneValidationFailure("TvCategory", "Category does not exist")
|
||||||
|
{
|
||||||
|
InfoLink = String.Format("http://{0}:{1}/", Settings.Host, Settings.Port),
|
||||||
|
DetailedDescription = "The Category your entered doesn't exist in NzbGet. Go to NzbGet to create it."
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -193,7 +193,12 @@ private void CheckForError(IRestResponse response)
|
|||||||
{
|
{
|
||||||
if (response.ResponseStatus != ResponseStatus.Completed)
|
if (response.ResponseStatus != ResponseStatus.Completed)
|
||||||
{
|
{
|
||||||
throw new DownloadClientException("Unable to connect to NzbGet, please check your settings");
|
throw new DownloadClientException("Unable to connect to NzbGet, please check your settings", response.ErrorException);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
throw new DownloadClientException("Authentication failed for NzbGet, please check your settings", response.ErrorException);
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = Json.Deserialize<JsonError>(response.Content);
|
var result = Json.Deserialize<JsonError>(response.Content);
|
||||||
|
@ -95,13 +95,9 @@ public override DownloadClientStatus GetStatus()
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ValidationResult Test()
|
protected override void Test(List<ValidationFailure> failures)
|
||||||
{
|
{
|
||||||
var failures = new List<ValidationFailure>();
|
|
||||||
|
|
||||||
failures.AddIfNotNull(TestWrite(Settings.NzbFolder, "NzbFolder"));
|
failures.AddIfNotNull(TestWrite(Settings.NzbFolder, "NzbFolder"));
|
||||||
|
|
||||||
return new ValidationResult(failures);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValidationFailure TestWrite(String folder, String propertyName)
|
private ValidationFailure TestWrite(String folder, String propertyName)
|
||||||
|
@ -303,19 +303,16 @@ public override DownloadClientStatus GetStatus()
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ValidationResult Test()
|
protected override void Test(List<ValidationFailure> failures)
|
||||||
{
|
{
|
||||||
var failures = new List<ValidationFailure>();
|
|
||||||
|
|
||||||
failures.AddIfNotNull(TestConnection());
|
failures.AddIfNotNull(TestConnection());
|
||||||
|
failures.AddIfNotNull(TestAuthentication());
|
||||||
failures.AddIfNotNull(TestCategory());
|
failures.AddIfNotNull(TestCategory());
|
||||||
|
|
||||||
if (!Settings.TvCategoryLocalPath.IsNullOrWhiteSpace())
|
if (!Settings.TvCategoryLocalPath.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
failures.AddIfNotNull(TestFolder(Settings.TvCategoryLocalPath, "TvCategoryLocalPath"));
|
failures.AddIfNotNull(TestFolder(Settings.TvCategoryLocalPath, "TvCategoryLocalPath"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ValidationResult(failures);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValidationFailure TestConnection()
|
private ValidationFailure TestConnection()
|
||||||
@ -333,6 +330,28 @@ private ValidationFailure TestConnection()
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ValidationFailure TestAuthentication()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_proxy.GetConfig(Settings);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (ex.Message.ContainsIgnoreCase("API Key Incorrect"))
|
||||||
|
{
|
||||||
|
return new ValidationFailure("APIKey", "API Key Incorrect");
|
||||||
|
}
|
||||||
|
if (ex.Message.ContainsIgnoreCase("API Key Required"))
|
||||||
|
{
|
||||||
|
return new ValidationFailure("APIKey", "API Key Required");
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private ValidationFailure TestCategory()
|
private ValidationFailure TestCategory()
|
||||||
{
|
{
|
||||||
var config = this._proxy.GetConfig(Settings);
|
var config = this._proxy.GetConfig(Settings);
|
||||||
|
@ -145,7 +145,7 @@ private void CheckForError(IRestResponse response)
|
|||||||
{
|
{
|
||||||
if (response.ResponseStatus != ResponseStatus.Completed)
|
if (response.ResponseStatus != ResponseStatus.Completed)
|
||||||
{
|
{
|
||||||
throw new DownloadClientException("Unable to connect to SABnzbd, please check your settings");
|
throw new DownloadClientException("Unable to connect to SABnzbd, please check your settings", response.ErrorException);
|
||||||
}
|
}
|
||||||
|
|
||||||
SabnzbdJsonError result;
|
SabnzbdJsonError result;
|
||||||
|
@ -143,14 +143,10 @@ public override DownloadClientStatus GetStatus()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ValidationResult Test()
|
protected override void Test(List<ValidationFailure> failures)
|
||||||
{
|
{
|
||||||
var failures = new List<ValidationFailure>();
|
|
||||||
|
|
||||||
failures.AddIfNotNull(TestFolder(Settings.NzbFolder, "NzbFolder"));
|
failures.AddIfNotNull(TestFolder(Settings.NzbFolder, "NzbFolder"));
|
||||||
failures.AddIfNotNull(TestFolder(Settings.WatchFolder, "WatchFolder"));
|
failures.AddIfNotNull(TestFolder(Settings.WatchFolder, "WatchFolder"));
|
||||||
|
|
||||||
return new ValidationResult(failures);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NLog;
|
using NLog;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
|
using NzbDrone.Core.Validation;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download
|
namespace NzbDrone.Core.Download
|
||||||
{
|
{
|
||||||
@ -39,7 +40,6 @@ public IEnumerable<ProviderDefinition> DefaultDefinitions
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ProviderDefinition Definition { get; set; }
|
public ProviderDefinition Definition { get; set; }
|
||||||
public abstract ValidationResult Test();
|
|
||||||
|
|
||||||
protected TSettings Settings
|
protected TSettings Settings
|
||||||
{
|
{
|
||||||
@ -101,11 +101,33 @@ protected void RemapStorage(DownloadClientItem downloadClientItem, String remote
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ValidationResult Test()
|
||||||
|
{
|
||||||
|
var failures = new List<ValidationFailure>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Test(failures);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Test aborted due to exception", ex);
|
||||||
|
failures.Add(new ValidationFailure(string.Empty, "Test was aborted due to an error: " + ex.Message));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ValidationResult(failures);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void Test(List<ValidationFailure> failures);
|
||||||
|
|
||||||
protected ValidationFailure TestFolder(String folder, String propertyName, Boolean mustBeWritable = true)
|
protected ValidationFailure TestFolder(String folder, String propertyName, Boolean mustBeWritable = true)
|
||||||
{
|
{
|
||||||
if (!_diskProvider.FolderExists(folder))
|
if (!_diskProvider.FolderExists(folder))
|
||||||
{
|
{
|
||||||
return new ValidationFailure(propertyName, "Folder does not exist");
|
return new NzbDroneValidationFailure(propertyName, "Folder does not exist")
|
||||||
|
{
|
||||||
|
DetailedDescription = "The folder you specified does not exist or is inaccessible. Please verify the folder permissions for the user account that is used to execute NzbDrone."
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mustBeWritable)
|
if (mustBeWritable)
|
||||||
@ -119,7 +141,10 @@ protected ValidationFailure TestFolder(String folder, String propertyName, Boole
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.ErrorException(ex.Message, ex);
|
_logger.ErrorException(ex.Message, ex);
|
||||||
return new ValidationFailure(propertyName, "Unable to write to folder");
|
return new NzbDroneValidationFailure(propertyName, "Unable to write to folder")
|
||||||
|
{
|
||||||
|
DetailedDescription = "The folder you specified is not writable. Please verify the folder permissions for the user account that is used to execute NzbDrone."
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user