diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserProxy.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserProxy.cs index 9a2ebda6f..b6a5554ed 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserProxy.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserProxy.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net; using NLog; using NzbDrone.Common.Http; using NzbDrone.Common.Serializer; @@ -20,6 +19,16 @@ public MediaBrowserProxy(IHttpClient httpClient, Logger logger) _logger = logger; } + public void TestConnection(MediaBrowserSettings settings) + { + var path = "/System/Configuration"; + var request = BuildRequest(path, settings); + request.Headers.Add("X-MediaBrowser-Token", settings.ApiKey); + + var response = _httpClient.Get(request); + _logger.Trace("Response: {0}", response.Content); + } + public void Notify(MediaBrowserSettings settings, string title, string message) { var path = "/Notifications/Admin"; @@ -34,21 +43,7 @@ public void Notify(MediaBrowserSettings settings, string title, string message) ImageUrl = "https://raw.github.com/Sonarr/Sonarr/develop/Logo/64.png" }.ToJson()); - try - { - ProcessRequest(request, settings); - } - catch (HttpException e) - { - if (e.Response.StatusCode == HttpStatusCode.NotFound) - { - _logger.Warn("Unable to send notification to Emby. If you're using Jellyfin disable 'Send Notifications'"); - } - else - { - throw; - } - } + ProcessRequest(request, settings); } public HashSet GetPaths(MediaBrowserSettings settings, Series series) diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs index a8a535b05..48702bb40 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs @@ -62,8 +62,7 @@ public ValidationFailure Test(MediaBrowserSettings settings) try { _logger.Debug("Testing connection to Emby/Jellyfin : {0}", settings.Address); - - Notify(settings, "Test from Sonarr", "Success! MediaBrowser has been successfully configured!"); + _proxy.TestConnection(settings); } catch (HttpException ex) { @@ -71,6 +70,11 @@ public ValidationFailure Test(MediaBrowserSettings settings) { return new ValidationFailure("ApiKey", _localizationService.GetLocalizedString("NotificationsValidationInvalidApiKey")); } + else + { + _logger.Trace(ex, "Error when connecting to Emby/Jellyfin"); + return new ValidationFailure("Host", _localizationService.GetLocalizedString("NotificationsValidationUnableToSendTestMessage", new Dictionary { { "exceptionMessage", ex.Message } })); + } } catch (Exception ex) { @@ -78,6 +82,25 @@ public ValidationFailure Test(MediaBrowserSettings settings) return new ValidationFailure("Host", _localizationService.GetLocalizedString("NotificationsValidationUnableToSendTestMessage", new Dictionary { { "exceptionMessage", ex.Message } })); } + if (settings.Notify) + { + try + { + Notify(settings, "Test from Sonarr", "Success! MediaBrowser has been successfully configured!"); + } + catch (HttpException ex) + { + if (ex.Response.StatusCode == HttpStatusCode.NotFound) + { + return new ValidationFailure("Notify", "Unable to send notification to Emby. If you're using Jellyfin disable 'Send Notifications'"); + } + else + { + throw; + } + } + } + return null; } }