From 10ef372cfd81a76dd270474adc2444fce0d30d9f Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 17 Feb 2017 22:37:19 +0000 Subject: [PATCH] Added some debugging code around the newsletter for Emby #1116 --- Ombi.Api/EmbyApi.cs | 89 +++++++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 23 deletions(-) diff --git a/Ombi.Api/EmbyApi.cs b/Ombi.Api/EmbyApi.cs index f703c0570..83028153a 100644 --- a/Ombi.Api/EmbyApi.cs +++ b/Ombi.Api/EmbyApi.cs @@ -33,6 +33,7 @@ using NLog; using Ombi.Api.Interfaces; using Ombi.Api.Models.Emby; using Ombi.Helpers; +using Polly; using RestSharp; namespace Ombi.Api @@ -78,7 +79,7 @@ namespace Ombi.Api Resource = "emby/System/Info", Method = Method.GET }; - + AddHeaders(request, apiKey); var policy = RetryHandler.RetryAndWaitPolicy((exception, timespan) => Log.Error(exception, "Exception when calling GetSystemInformation for Emby, Retrying {0}", timespan), new[] { @@ -162,29 +163,71 @@ namespace Ombi.Api TimeSpan.FromSeconds(5) }); - switch (type) + IRestResponse response = null; + try + { + + switch (type) + { + case EmbyMediaType.Movie: + response = policy.Execute(() => Api.Execute(request, baseUri)); + break; + + case EmbyMediaType.Series: + response = policy.Execute(() => Api.Execute(request, baseUri)); + break; + case EmbyMediaType.Music: + break; + case EmbyMediaType.Episode: + response = policy.Execute(() => Api.Execute(request, baseUri)); + break; + default: + throw new ArgumentOutOfRangeException(nameof(type), type, null); + } + + var info = new EmbyInformation(); + + switch (type) + { + case EmbyMediaType.Movie: + return new EmbyInformation + { + MovieInformation = JsonConvert.DeserializeObject(response.Content) + }; + case EmbyMediaType.Series: + return new EmbyInformation + { + SeriesInformation = JsonConvert.DeserializeObject(response.Content) + }; + case EmbyMediaType.Music: + break; + case EmbyMediaType.Episode: + return new EmbyInformation + { + EpisodeInformation = JsonConvert.DeserializeObject(response.Content) + }; + default: + throw new ArgumentOutOfRangeException(nameof(type), type, null); + } + + } + catch (Exception e) { - case EmbyMediaType.Movie: - return new EmbyInformation - { - MovieInformation = policy.Execute(() => Api.ExecuteJson(request, baseUri)) - }; - case EmbyMediaType.Series: - return new EmbyInformation - { - SeriesInformation = - policy.Execute(() => Api.ExecuteJson(request, baseUri)) - }; - case EmbyMediaType.Music: - break; - case EmbyMediaType.Episode: - return new EmbyInformation - { - EpisodeInformation = - policy.Execute(() => Api.ExecuteJson(request, baseUri)) - }; - default: - throw new ArgumentOutOfRangeException(nameof(type), type, null); + Log.Error("Could not get the media item's information"); + Log.Error(e); + Log.Debug("ResponseContent"); + Log.Debug(response?.Content ?? "Empty"); + Log.Debug("ResponseStatusCode"); + Log.Debug(response?.StatusCode ?? HttpStatusCode.PreconditionFailed); + + Log.Debug("ResponseError"); + Log.Debug(response?.ErrorMessage ?? "No Error"); + Log.Debug("ResponseException"); + Log.Debug(response?.ErrorException ?? new Exception()); + + + + throw; } return new EmbyInformation(); }