diff --git a/src/NzbDrone.Api/Commands/CommandModule.cs b/src/NzbDrone.Api/Commands/CommandModule.cs index fcaeef9c4..1395d68ec 100644 --- a/src/NzbDrone.Api/Commands/CommandModule.cs +++ b/src/NzbDrone.Api/Commands/CommandModule.cs @@ -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 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; diff --git a/src/NzbDrone.Api/Series/MovieModule.cs b/src/NzbDrone.Api/Series/MovieModule.cs index 06e5c7d02..5a6fc28bf 100644 --- a/src/NzbDrone.Api/Series/MovieModule.cs +++ b/src/NzbDrone.Api/Series/MovieModule.cs @@ -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 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)