Add try catch block

pull/3393/head
David 4 years ago
parent 9a223b7359
commit fae510308e

@ -14,6 +14,7 @@ using MediaBrowser.Model.Plugins;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.Controllers namespace Jellyfin.Api.Controllers
{ {
@ -22,6 +23,7 @@ namespace Jellyfin.Api.Controllers
/// </summary> /// </summary>
public class DashboardController : BaseJellyfinApiController public class DashboardController : BaseJellyfinApiController
{ {
private readonly ILogger<DashboardController> _logger;
private readonly IServerApplicationHost _appHost; private readonly IServerApplicationHost _appHost;
private readonly IConfiguration _appConfig; private readonly IConfiguration _appConfig;
private readonly IServerConfigurationManager _serverConfigurationManager; private readonly IServerConfigurationManager _serverConfigurationManager;
@ -30,16 +32,19 @@ namespace Jellyfin.Api.Controllers
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DashboardController"/> class. /// Initializes a new instance of the <see cref="DashboardController"/> class.
/// </summary> /// </summary>
/// <param name="logger">Instance of <see cref="ILogger{DashboardController}"/> interface.</param>
/// <param name="appHost">Instance of <see cref="IServerApplicationHost"/> interface.</param> /// <param name="appHost">Instance of <see cref="IServerApplicationHost"/> interface.</param>
/// <param name="appConfig">Instance of <see cref="IConfiguration"/> interface.</param> /// <param name="appConfig">Instance of <see cref="IConfiguration"/> interface.</param>
/// <param name="resourceFileManager">Instance of <see cref="IResourceFileManager"/> interface.</param> /// <param name="resourceFileManager">Instance of <see cref="IResourceFileManager"/> interface.</param>
/// <param name="serverConfigurationManager">Instance of <see cref="IServerConfigurationManager"/> interface.</param> /// <param name="serverConfigurationManager">Instance of <see cref="IServerConfigurationManager"/> interface.</param>
public DashboardController( public DashboardController(
ILogger<DashboardController> logger,
IServerApplicationHost appHost, IServerApplicationHost appHost,
IConfiguration appConfig, IConfiguration appConfig,
IResourceFileManager resourceFileManager, IResourceFileManager resourceFileManager,
IServerConfigurationManager serverConfigurationManager) IServerConfigurationManager serverConfigurationManager)
{ {
_logger = logger;
_appHost = appHost; _appHost = appHost;
_appConfig = appConfig; _appConfig = appConfig;
_resourceFileManager = resourceFileManager; _resourceFileManager = resourceFileManager;
@ -63,7 +68,7 @@ namespace Jellyfin.Api.Controllers
[HttpGet("/web/ConfigurationPages")] [HttpGet("/web/ConfigurationPages")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<IEnumerable<ConfigurationPageInfo>> GetConfigurationPages( public ActionResult<IEnumerable<ConfigurationPageInfo?>> GetConfigurationPages(
[FromQuery] bool? enableInMainMenu, [FromQuery] bool? enableInMainMenu,
[FromQuery] ConfigurationPageType? pageType) [FromQuery] ConfigurationPageType? pageType)
{ {
@ -79,7 +84,15 @@ namespace Jellyfin.Api.Controllers
// Don't allow a failing plugin to fail them all // Don't allow a failing plugin to fail them all
var configPages = pages.Select(p => var configPages = pages.Select(p =>
{ {
return new ConfigurationPageInfo(p); try
{
return new ConfigurationPageInfo(p);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting plugin information from {Plugin}", p.GetType().Name);
return null;
}
}) })
.Where(i => i != null) .Where(i => i != null)
.ToList(); .ToList();
@ -88,12 +101,12 @@ namespace Jellyfin.Api.Controllers
if (pageType.HasValue) if (pageType.HasValue)
{ {
configPages = configPages.Where(p => p.ConfigurationPageType == pageType).ToList(); configPages = configPages.Where(p => p!.ConfigurationPageType == pageType).ToList();
} }
if (enableInMainMenu.HasValue) if (enableInMainMenu.HasValue)
{ {
configPages = configPages.Where(p => p.EnableInMainMenu == enableInMainMenu.Value).ToList(); configPages = configPages.Where(p => p!.EnableInMainMenu == enableInMainMenu.Value).ToList();
} }
return configPages; return configPages;

Loading…
Cancel
Save