diff --git a/src/Ombi/ClientApp/app/interfaces/IPlex.ts b/src/Ombi/ClientApp/app/interfaces/IPlex.ts index 286ca994b..9213db550 100644 --- a/src/Ombi/ClientApp/app/interfaces/IPlex.ts +++ b/src/Ombi/ClientApp/app/interfaces/IPlex.ts @@ -14,6 +14,12 @@ export interface IPlexLibraries { mediaContainer: IMediaContainer; } +export interface IPlexLibResponse { + successful: boolean; + message: string; + data:IPlexLibraries; +} + export interface IMediaContainer { directory: IDirectory[]; } diff --git a/src/Ombi/ClientApp/app/services/applications/plex.service.ts b/src/Ombi/ClientApp/app/services/applications/plex.service.ts index de71f6ccb..75e2d8148 100644 --- a/src/Ombi/ClientApp/app/services/applications/plex.service.ts +++ b/src/Ombi/ClientApp/app/services/applications/plex.service.ts @@ -6,7 +6,7 @@ import { Observable } from "rxjs/Rx"; import { ServiceAuthHelpers } from "../service.helpers"; -import { IPlexAuthentication, IPlexLibraries, IPlexServerViewModel } from "../../interfaces"; +import { IPlexAuthentication, IPlexLibResponse, IPlexServerViewModel } from "../../interfaces"; import { IPlexServer } from "../../interfaces"; @Injectable() @@ -23,7 +23,7 @@ export class PlexService extends ServiceAuthHelpers { return this.http.post(`${this.url}servers`, JSON.stringify({ login, password }), { headers: this.headers }).map(this.extractData); } - public getLibraries(plexSettings: IPlexServer): Observable { + public getLibraries(plexSettings: IPlexServer): Observable { return this.http.post(`${this.url}Libraries`, JSON.stringify(plexSettings), { headers: this.headers }).map(this.extractData).catch(this.handleError); } diff --git a/src/Ombi/ClientApp/app/services/service.helpers.ts b/src/Ombi/ClientApp/app/services/service.helpers.ts index 8a8019651..702b6db3c 100644 --- a/src/Ombi/ClientApp/app/services/service.helpers.ts +++ b/src/Ombi/ClientApp/app/services/service.helpers.ts @@ -1,4 +1,5 @@ import { Headers, Http, Response } from "@angular/http"; +import "rxjs/add/observable/throw"; import { Observable } from "rxjs/Observable"; import { AuthHttp } from "angular2-jwt"; diff --git a/src/Ombi/ClientApp/app/settings/emby/emby.component.ts b/src/Ombi/ClientApp/app/settings/emby/emby.component.ts index d1c84a4aa..522490e0c 100644 --- a/src/Ombi/ClientApp/app/settings/emby/emby.component.ts +++ b/src/Ombi/ClientApp/app/settings/emby/emby.component.ts @@ -39,7 +39,7 @@ export class EmbyComponent implements OnInit { public test(server: IEmbyServer) { this.testerService.embyTest(server).subscribe(x => { - if (x) { + if (x === true) { this.notificationService.success("Connected", `Successfully connected to the Emby server ${server.name}!`); } else { this.notificationService.error("Connected", `We could not connect to the Emby server ${server.name}!`); diff --git a/src/Ombi/ClientApp/app/settings/plex/plex.component.ts b/src/Ombi/ClientApp/app/settings/plex/plex.component.ts index 52136b271..19b9417d1 100644 --- a/src/Ombi/ClientApp/app/settings/plex/plex.component.ts +++ b/src/Ombi/ClientApp/app/settings/plex/plex.component.ts @@ -60,7 +60,7 @@ export class PlexComponent implements OnInit, OnDestroy { public testPlex(server: IPlexServer) { this.testerService.plexTest(server).subscribe(x => { - if (x) { + if (x === true) { this.notificationService.success("Connected", `Successfully connected to the Plex server ${server.name}!`); } else { this.notificationService.error("Connected", `We could not connect to the Plex server ${server.name}!`); @@ -90,15 +90,19 @@ export class PlexComponent implements OnInit, OnDestroy { } this.plexService.getLibraries(server).subscribe(x => { server.plexSelectedLibraries = []; - x.mediaContainer.directory.forEach((item, index) => { - const lib: IPlexLibrariesSettings = { - key: item.key, - title: item.title, - enabled: false, - }; - server.plexSelectedLibraries.push(lib); - }); - }, + if (x.successful) { + x.data.mediaContainer.directory.forEach((item) => { + const lib: IPlexLibrariesSettings = { + key: item.key, + title: item.title, + enabled: false, + }; + server.plexSelectedLibraries.push(lib); + }); + } else { + this.notificationService.error("Error", x.message); + } + }, err => { this.notificationService.error("Error", err); }); } diff --git a/src/Ombi/Controllers/External/PlexController.cs b/src/Ombi/Controllers/External/PlexController.cs index b9d0446f6..b04e08650 100644 --- a/src/Ombi/Controllers/External/PlexController.cs +++ b/src/Ombi/Controllers/External/PlexController.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Ombi.Api.Plex; using Ombi.Api.Plex.Models; using Ombi.Attributes; @@ -18,14 +19,17 @@ namespace Ombi.Controllers.External [Produces("application/json")] public class PlexController : Controller { - public PlexController(IPlexApi plexApi, ISettingsService plexSettings) + public PlexController(IPlexApi plexApi, ISettingsService plexSettings, + ILogger logger) { PlexApi = plexApi; PlexSettings = plexSettings; + _log = logger; } private IPlexApi PlexApi { get; } private ISettingsService PlexSettings { get; } + private readonly ILogger _log; /// /// Signs into the Plex API. @@ -88,11 +92,29 @@ namespace Ombi.Controllers.External /// The settings. /// [HttpPost("Libraries")] - public async Task GetPlexLibraries([FromBody] PlexServers settings) + public async Task GetPlexLibraries([FromBody] PlexServers settings) { - var libs = await PlexApi.GetLibrarySections(settings.PlexAuthToken, settings.FullUri); + try + { + var libs = await PlexApi.GetLibrarySections(settings.PlexAuthToken, settings.FullUri); + + return new PlexLibrariesResponse + { + Successful = true, + Data = libs + }; + } + catch (Exception e) + { + _log.LogWarning(e,"Error thrown when attempting to obtain the plex libs"); - return libs; + var message = e.InnerException != null ? $"{e.Message} - {e.InnerException.Message}" : e.Message; + return new PlexLibrariesResponse + { + Successful = false, + Message = message + }; + } } /// diff --git a/src/Ombi/Models/External/PlexLibrariesResponse.cs b/src/Ombi/Models/External/PlexLibrariesResponse.cs new file mode 100644 index 000000000..d1033f12e --- /dev/null +++ b/src/Ombi/Models/External/PlexLibrariesResponse.cs @@ -0,0 +1,38 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: PlexLibrariesResponse.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 + +using Ombi.Api.Plex.Models; + +namespace Ombi.Models.External +{ + public class PlexLibrariesResponse + { + public PlexContainer Data { get; set; } + public bool Successful { get; set; } + public string Message { get; set; } + } +} \ No newline at end of file