diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
index 1ec1a67ae..d67958e0d 100644
--- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
+++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
@@ -64,6 +64,7 @@
+
diff --git a/PlexRequests.Api.Models/Sonarr/SonarrAddSeries.cs b/PlexRequests.Api.Models/Sonarr/SonarrAddSeries.cs
index 534f3068f..23540521f 100644
--- a/PlexRequests.Api.Models/Sonarr/SonarrAddSeries.cs
+++ b/PlexRequests.Api.Models/Sonarr/SonarrAddSeries.cs
@@ -1,5 +1,7 @@
using System.Collections.Generic;
+using Newtonsoft.Json;
+
namespace PlexRequests.Api.Models.Sonarr
{
public class Season
@@ -23,6 +25,8 @@ namespace PlexRequests.Api.Models.Sonarr
public string imdbId { get; set; }
public string titleSlug { get; set; }
public int id { get; set; }
+ [JsonIgnore]
+ public string ErrorMessage { get; set; }
}
public class AddOptions
diff --git a/PlexRequests.Api.Models/Sonarr/SonarrError.cs b/PlexRequests.Api.Models/Sonarr/SonarrError.cs
new file mode 100644
index 000000000..ae3fbdfca
--- /dev/null
+++ b/PlexRequests.Api.Models/Sonarr/SonarrError.cs
@@ -0,0 +1,36 @@
+#region Copyright
+// /************************************************************************
+// Copyright (c) 2016 Jamie Rees
+// File: SonarrError.cs
+// Created By: Jamie Rees
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+// ************************************************************************/
+#endregion
+namespace PlexRequests.Api.Models.Sonarr
+{
+ public class SonarrError
+ {
+ public string propertyName { get; set; }
+ public string errorMessage { get; set; }
+ public string attemptedValue { get; set; }
+ public string[] formattedMessageArguments { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/PlexRequests.Api/ApiRequest.cs b/PlexRequests.Api/ApiRequest.cs
index 62391386b..ad056fbfe 100644
--- a/PlexRequests.Api/ApiRequest.cs
+++ b/PlexRequests.Api/ApiRequest.cs
@@ -26,13 +26,9 @@
#endregion
using System;
using System.IO;
-using System.Net;
-using System.Text;
-using System.Xml;
using System.Xml.Serialization;
using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
using NLog;
@@ -99,17 +95,18 @@ namespace PlexRequests.Api
try
{
var json = JsonConvert.DeserializeObject(response.Content);
+
return json;
}
catch (Exception e)
{
- Log.Fatal(e);
- Log.Info(response.Content);
+ Log.Error(e);
+ Log.Error(response.Content);
throw;
}
}
- public T DeserializeXml(string input)
+ private T DeserializeXml(string input)
where T : class
{
var ser = new XmlSerializer(typeof(T));
diff --git a/PlexRequests.Api/SonarrApi.cs b/PlexRequests.Api/SonarrApi.cs
index 1d1a57f34..d70ba2eef 100644
--- a/PlexRequests.Api/SonarrApi.cs
+++ b/PlexRequests.Api/SonarrApi.cs
@@ -30,6 +30,8 @@ using System.Linq;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Sonarr;
+using PlexRequests.Helpers;
+
using RestSharp;
namespace PlexRequests.Api
@@ -56,7 +58,8 @@ namespace PlexRequests.Api
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl)
{
-
+ Log.Debug("Adding series {0}", title);
+ Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount);
var request = new RestRequest
{
Resource = "/api/Series?",
@@ -74,7 +77,6 @@ namespace PlexRequests.Api
rootFolderPath = rootPath
};
-
for (var i = 1; i <= seasonCount; i++)
{
var season = new Season
@@ -85,11 +87,20 @@ namespace PlexRequests.Api
options.seasons.Add(season);
}
+ Log.Debug("Sonarr API Options:");
+ Log.Debug(options.DumpJson());
+
request.AddHeader("X-Api-Key", apiKey);
request.AddJsonBody(options);
var obj = Api.ExecuteJson(request, baseUrl);
+ if (obj == null)
+ {
+ var error = Api.ExecuteJson(request, baseUrl);
+ obj = new SonarrAddSeries { ErrorMessage = error.errorMessage };
+ }
+
return obj;
}
diff --git a/PlexRequests.UI/Helpers/TvSender.cs b/PlexRequests.UI/Helpers/TvSender.cs
index d26611321..703c813fd 100644
--- a/PlexRequests.UI/Helpers/TvSender.cs
+++ b/PlexRequests.UI/Helpers/TvSender.cs
@@ -24,17 +24,13 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
-
-using Nancy;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.SickRage;
using PlexRequests.Api.Models.Sonarr;
-using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Store;
-using PlexRequests.UI.Models;
namespace PlexRequests.UI.Helpers
{
diff --git a/PlexRequests.UI/Modules/ApprovalModule.cs b/PlexRequests.UI/Modules/ApprovalModule.cs
index b2c6217bb..1e129e3b3 100644
--- a/PlexRequests.UI/Modules/ApprovalModule.cs
+++ b/PlexRequests.UI/Modules/ApprovalModule.cs
@@ -131,7 +131,7 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new JsonResponseModel
{
Result = false,
- Message = "Could not add the series to Sonarr"
+ Message = result.ErrorMessage ?? "Could not add the series to Sonarr"
});
}
@@ -276,7 +276,7 @@ namespace PlexRequests.UI.Modules
if (sonarr.Enabled)
{
var result = sender.SendToSonarr(sonarr, r);
- if (result != null)
+ if (!string.IsNullOrEmpty(result?.title))
{
r.Approved = true;
updatedRequests.Add(r);
@@ -284,6 +284,7 @@ namespace PlexRequests.UI.Modules
else
{
Log.Error("Could not approve and send the TV {0} to Sonarr!", r.Title);
+ Log.Error("Error message: {0}", result?.ErrorMessage);
}
}
}
diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs
index 2a98e8933..9b307f983 100644
--- a/PlexRequests.UI/Modules/SearchModule.cs
+++ b/PlexRequests.UI/Modules/SearchModule.cs
@@ -371,18 +371,19 @@ namespace PlexRequests.UI.Modules
if (sonarrSettings.Enabled)
{
var result = sender.SendToSonarr(sonarrSettings, model);
- if (result != null)
+ if (result != null && !string.IsNullOrEmpty(result.title))
{
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
RequestService.AddRequest(model);
+ var notify1 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
+ NotificationService.Publish(notify1);
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
}
- var notify1 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
- NotificationService.Publish(notify1);
- return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to Sonarr! Please check your settings." });
+
+ return Response.AsJson(new JsonResponseModel { Result = false, Message = result?.ErrorMessage ?? "Something went wrong adding the movie to Sonarr! Please check your settings." });
}