1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Hopefully more logging to catch errors better.

This commit is contained in:
Leonardo Galli 2017-05-08 18:46:03 +02:00
parent 98b6932ffe
commit d133ee3143
2 changed files with 40 additions and 7 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Api.Extensions;
using NzbDrone.Api.Validation;
using NzbDrone.Common;
@ -17,14 +18,17 @@ public class CommandModule : NzbDroneRestModuleWithSignalR<CommandResource, Comm
{
private readonly IManageCommandQueue _commandQueueManager;
private readonly IServiceFactory _serviceFactory;
private readonly Logger _logger;
public CommandModule(IManageCommandQueue commandQueueManager,
IBroadcastSignalRMessage signalRBroadcaster,
IServiceFactory serviceFactory)
IServiceFactory serviceFactory,
Logger logger)
: base(signalRBroadcaster)
{
_commandQueueManager = commandQueueManager;
_serviceFactory = serviceFactory;
_logger = logger;
GetResourceById = GetCommand;
CreateResource = StartCommand;
@ -41,7 +45,13 @@ private CommandResource GetCommand(int id)
private int StartCommand(CommandResource commandResource)
{
var commandType = _serviceFactory.GetImplementations(typeof(Command))
.Single(c => c.Name.Replace("Command", "").Equals(commandResource.Name, StringComparison.InvariantCultureIgnoreCase));
.SingleOrDefault(c => c.Name.Replace("Command", "").Equals(commandResource.Name, StringComparison.InvariantCultureIgnoreCase));
if (commandType == null)
{
_logger.Error("Found no matching command for {0}", commandResource.Name);
return 0;
}
dynamic command = Request.Body.FromJson(commandType);
command.Trigger = CommandTrigger.Manual;

View File

@ -17,6 +17,8 @@
using NzbDrone.Core.Validation;
using NzbDrone.SignalR;
using NzbDrone.Core.Datastore;
using Microsoft.CSharp.RuntimeBinder;
using Nancy;
namespace NzbDrone.Api.Movie
{
@ -58,9 +60,12 @@ ProfileExistsValidator profileExistsValidator
GetResourceAll = AllMovie;
GetResourcePaged = GetMoviePaged;
GetResourceById = GetMovie;
Get[TITLE_SLUG_ROUTE] = (options) => {
return ReqResExtensions.AsResponse(GetByTitleSlug(options.slug));
};
Get[TITLE_SLUG_ROUTE] = GetByTitleSlug; /*(options) => {
return ReqResExtensions.AsResponse(GetByTitleSlug(options.slug), Nancy.HttpStatusCode.OK);
};*/
CreateResource = AddMovie;
UpdateResource = UpdateMovie;
DeleteResource = DeleteMovie;
@ -145,9 +150,27 @@ private List<MovieResource> AllMovie()
return moviesResources;
}
private MovieResource GetByTitleSlug(string slug)
private Response GetByTitleSlug(dynamic options)
{
return MapToResource(_moviesService.FindByTitleSlug(slug));
var slug = "";
try
{
slug = options.slug;
// do stuff with x
}
catch (RuntimeBinderException)
{
return new NotFoundResponse();
}
try
{
return MapToResource(_moviesService.FindByTitleSlug(slug)).AsResponse(Nancy.HttpStatusCode.OK);
}
catch (ModelNotFoundException)
{
return new NotFoundResponse();
}
}
private int AddMovie(MovieResource moviesResource)