diff --git a/src/Radarr.Api.V3/Calendar/CalendarController.cs b/src/Radarr.Api.V3/Calendar/CalendarController.cs index b4e6a0e5f..8d983463c 100644 --- a/src/Radarr.Api.V3/Calendar/CalendarController.cs +++ b/src/Radarr.Api.V3/Calendar/CalendarController.cs @@ -35,7 +35,7 @@ namespace Radarr.Api.V3.Calendar _configService = configService; } - public override MovieResource GetResourceById(int id) + protected override MovieResource GetResourceById(int id) { throw new NotImplementedException(); } diff --git a/src/Radarr.Api.V3/Commands/CommandController.cs b/src/Radarr.Api.V3/Commands/CommandController.cs index 88462649b..20a3b8e80 100644 --- a/src/Radarr.Api.V3/Commands/CommandController.cs +++ b/src/Radarr.Api.V3/Commands/CommandController.cs @@ -41,7 +41,7 @@ namespace Radarr.Api.V3.Commands PostValidator.RuleFor(c => c.Name).NotBlank(); } - public override CommandResource GetResourceById(int id) + protected override CommandResource GetResourceById(int id) { return _commandQueueManager.Get(id).ToResource(); } diff --git a/src/Radarr.Api.V3/Config/ConfigController.cs b/src/Radarr.Api.V3/Config/ConfigController.cs index 02aa79501..e9ab4cbfe 100644 --- a/src/Radarr.Api.V3/Config/ConfigController.cs +++ b/src/Radarr.Api.V3/Config/ConfigController.cs @@ -17,7 +17,7 @@ namespace Radarr.Api.V3.Config _configService = configService; } - public override TResource GetResourceById(int id) + protected override TResource GetResourceById(int id) { return GetConfig(); } diff --git a/src/Radarr.Api.V3/Config/HostConfigController.cs b/src/Radarr.Api.V3/Config/HostConfigController.cs index f19b0ca83..21d381820 100644 --- a/src/Radarr.Api.V3/Config/HostConfigController.cs +++ b/src/Radarr.Api.V3/Config/HostConfigController.cs @@ -78,7 +78,7 @@ namespace Radarr.Api.V3.Config return cert != null; } - public override HostConfigResource GetResourceById(int id) + protected override HostConfigResource GetResourceById(int id) { return GetHostConfig(); } diff --git a/src/Radarr.Api.V3/Config/NamingConfigController.cs b/src/Radarr.Api.V3/Config/NamingConfigController.cs index 3d7d55af8..92f234a30 100644 --- a/src/Radarr.Api.V3/Config/NamingConfigController.cs +++ b/src/Radarr.Api.V3/Config/NamingConfigController.cs @@ -33,7 +33,7 @@ namespace Radarr.Api.V3.Config SharedValidator.RuleFor(c => c.MovieFolderFormat).ValidMovieFolderFormat(); } - public override NamingConfigResource GetResourceById(int id) + protected override NamingConfigResource GetResourceById(int id) { return GetNamingConfig(); } diff --git a/src/Radarr.Api.V3/Credits/CreditController.cs b/src/Radarr.Api.V3/Credits/CreditController.cs index 2f4e9feb9..10e4be516 100644 --- a/src/Radarr.Api.V3/Credits/CreditController.cs +++ b/src/Radarr.Api.V3/Credits/CreditController.cs @@ -16,7 +16,7 @@ namespace Radarr.Api.V3.Credits _creditService = creditService; } - public override CreditResource GetResourceById(int id) + protected override CreditResource GetResourceById(int id) { return _creditService.GetById(id).ToResource(); } diff --git a/src/Radarr.Api.V3/CustomFilters/CustomFilterController.cs b/src/Radarr.Api.V3/CustomFilters/CustomFilterController.cs index 0c20d4491..2fba4daa1 100644 --- a/src/Radarr.Api.V3/CustomFilters/CustomFilterController.cs +++ b/src/Radarr.Api.V3/CustomFilters/CustomFilterController.cs @@ -17,7 +17,7 @@ namespace Radarr.Api.V3.CustomFilters _customFilterService = customFilterService; } - public override CustomFilterResource GetResourceById(int id) + protected override CustomFilterResource GetResourceById(int id) { return _customFilterService.Get(id).ToResource(); } diff --git a/src/Radarr.Api.V3/CustomFormats/CustomFormatController.cs b/src/Radarr.Api.V3/CustomFormats/CustomFormatController.cs index dc735cc1e..29a6e720d 100644 --- a/src/Radarr.Api.V3/CustomFormats/CustomFormatController.cs +++ b/src/Radarr.Api.V3/CustomFormats/CustomFormatController.cs @@ -27,7 +27,7 @@ namespace Radarr.Api.V3.CustomFormats SharedValidator.RuleFor(c => c.Specifications).NotEmpty(); } - public override CustomFormatResource GetResourceById(int id) + protected override CustomFormatResource GetResourceById(int id) { return _formatService.GetById(id).ToResource(); } diff --git a/src/Radarr.Api.V3/Health/HealthController.cs b/src/Radarr.Api.V3/Health/HealthController.cs index c15825949..0f8103450 100644 --- a/src/Radarr.Api.V3/Health/HealthController.cs +++ b/src/Radarr.Api.V3/Health/HealthController.cs @@ -22,7 +22,7 @@ namespace Radarr.Api.V3.Health _healthCheckService = healthCheckService; } - public override HealthResource GetResourceById(int id) + protected override HealthResource GetResourceById(int id) { throw new NotImplementedException(); } diff --git a/src/Radarr.Api.V3/ImportLists/ImportExclusionsController.cs b/src/Radarr.Api.V3/ImportLists/ImportExclusionsController.cs index fec642cfc..18c3b8352 100644 --- a/src/Radarr.Api.V3/ImportLists/ImportExclusionsController.cs +++ b/src/Radarr.Api.V3/ImportLists/ImportExclusionsController.cs @@ -28,7 +28,7 @@ namespace Radarr.Api.V3.ImportLists return _exclusionService.GetAllExclusions().ToResource(); } - public override ImportExclusionsResource GetResourceById(int id) + protected override ImportExclusionsResource GetResourceById(int id) { return _exclusionService.GetById(id).ToResource(); } diff --git a/src/Radarr.Api.V3/Indexers/ReleaseControllerBase.cs b/src/Radarr.Api.V3/Indexers/ReleaseControllerBase.cs index 26e91fdb3..1a7e760b0 100644 --- a/src/Radarr.Api.V3/Indexers/ReleaseControllerBase.cs +++ b/src/Radarr.Api.V3/Indexers/ReleaseControllerBase.cs @@ -15,7 +15,7 @@ namespace Radarr.Api.V3.Indexers _qualityProfile = qualityProfileService.GetDefaultProfile(string.Empty); } - public override ReleaseResource GetResourceById(int id) + protected override ReleaseResource GetResourceById(int id) { throw new NotImplementedException(); } diff --git a/src/Radarr.Api.V3/MovieFiles/MovieFileController.cs b/src/Radarr.Api.V3/MovieFiles/MovieFileController.cs index cd60681bf..97f33b69c 100644 --- a/src/Radarr.Api.V3/MovieFiles/MovieFileController.cs +++ b/src/Radarr.Api.V3/MovieFiles/MovieFileController.cs @@ -47,7 +47,7 @@ namespace Radarr.Api.V3.MovieFiles _qualityUpgradableSpecification = qualityUpgradableSpecification; } - public override MovieFileResource GetResourceById(int id) + protected override MovieFileResource GetResourceById(int id) { var movieFile = _mediaFileService.GetMovie(id); var movie = _movieService.GetMovie(movieFile.MovieId); diff --git a/src/Radarr.Api.V3/Movies/AlternativeTitleController.cs b/src/Radarr.Api.V3/Movies/AlternativeTitleController.cs index 32fef37e6..00c9b23c0 100644 --- a/src/Radarr.Api.V3/Movies/AlternativeTitleController.cs +++ b/src/Radarr.Api.V3/Movies/AlternativeTitleController.cs @@ -17,7 +17,7 @@ namespace Radarr.Api.V3.Movies _altTitleService = altTitleService; } - public override AlternativeTitleResource GetResourceById(int id) + protected override AlternativeTitleResource GetResourceById(int id) { return _altTitleService.GetById(id).ToResource(); } diff --git a/src/Radarr.Api.V3/Movies/AlternativeYearController.cs b/src/Radarr.Api.V3/Movies/AlternativeYearController.cs index 083878844..3e80b5494 100644 --- a/src/Radarr.Api.V3/Movies/AlternativeYearController.cs +++ b/src/Radarr.Api.V3/Movies/AlternativeYearController.cs @@ -14,7 +14,7 @@ namespace Radarr.Api.V3.Movies _yearCache = cacheManager.GetCache(GetType(), "altYears"); } - public override AlternativeYearResource GetResourceById(int id) + protected override AlternativeYearResource GetResourceById(int id) { return new AlternativeYearResource { diff --git a/src/Radarr.Api.V3/Movies/MovieController.cs b/src/Radarr.Api.V3/Movies/MovieController.cs index 47f80f25c..23cc585fe 100644 --- a/src/Radarr.Api.V3/Movies/MovieController.cs +++ b/src/Radarr.Api.V3/Movies/MovieController.cs @@ -150,7 +150,7 @@ namespace Radarr.Api.V3.Movies return moviesResources; } - public override MovieResource GetResourceById(int id) + protected override MovieResource GetResourceById(int id) { var movie = _moviesService.GetMovie(id); return MapToResource(movie); diff --git a/src/Radarr.Api.V3/Movies/MovieImportController.cs b/src/Radarr.Api.V3/Movies/MovieImportController.cs index e7b630c5a..5c8f39974 100644 --- a/src/Radarr.Api.V3/Movies/MovieImportController.cs +++ b/src/Radarr.Api.V3/Movies/MovieImportController.cs @@ -17,7 +17,7 @@ namespace Radarr.Api.V3.Movies _addMovieService = addMovieService; } - public override MovieResource GetResourceById(int id) + protected override MovieResource GetResourceById(int id) { throw new NotImplementedException(); } diff --git a/src/Radarr.Api.V3/Movies/MovieLookupController.cs b/src/Radarr.Api.V3/Movies/MovieLookupController.cs index b360dce5e..3e2dde5e6 100644 --- a/src/Radarr.Api.V3/Movies/MovieLookupController.cs +++ b/src/Radarr.Api.V3/Movies/MovieLookupController.cs @@ -35,7 +35,7 @@ namespace Radarr.Api.V3.Movies _configService = configService; } - public override MovieResource GetResourceById(int id) + protected override MovieResource GetResourceById(int id) { throw new NotImplementedException(); } diff --git a/src/Radarr.Api.V3/Profiles/Delay/DelayProfileController.cs b/src/Radarr.Api.V3/Profiles/Delay/DelayProfileController.cs index a8ceacbf5..4de0e7efb 100644 --- a/src/Radarr.Api.V3/Profiles/Delay/DelayProfileController.cs +++ b/src/Radarr.Api.V3/Profiles/Delay/DelayProfileController.cs @@ -61,7 +61,7 @@ namespace Radarr.Api.V3.Profiles.Delay return Accepted(model.Id); } - public override DelayProfileResource GetResourceById(int id) + protected override DelayProfileResource GetResourceById(int id) { return _delayProfileService.Get(id).ToResource(); } diff --git a/src/Radarr.Api.V3/Profiles/Languages/LanguageController.cs b/src/Radarr.Api.V3/Profiles/Languages/LanguageController.cs index 9f62cf188..100f4aaf1 100644 --- a/src/Radarr.Api.V3/Profiles/Languages/LanguageController.cs +++ b/src/Radarr.Api.V3/Profiles/Languages/LanguageController.cs @@ -10,7 +10,7 @@ namespace Radarr.Api.V3.Profiles.Languages [V3ApiController] public class LanguageController : RestController { - public override LanguageResource GetResourceById(int id) + protected override LanguageResource GetResourceById(int id) { var language = (Language)id; diff --git a/src/Radarr.Api.V3/Profiles/Quality/QualityProfileController.cs b/src/Radarr.Api.V3/Profiles/Quality/QualityProfileController.cs index c8fb782b4..9b7f2bf23 100644 --- a/src/Radarr.Api.V3/Profiles/Quality/QualityProfileController.cs +++ b/src/Radarr.Api.V3/Profiles/Quality/QualityProfileController.cs @@ -68,7 +68,7 @@ namespace Radarr.Api.V3.Profiles.Quality return Accepted(model.Id); } - public override QualityProfileResource GetResourceById(int id) + protected override QualityProfileResource GetResourceById(int id) { return _profileService.Get(id).ToResource(); } diff --git a/src/Radarr.Api.V3/ProviderControllerBase.cs b/src/Radarr.Api.V3/ProviderControllerBase.cs index 53f6e7e9e..1a3052436 100644 --- a/src/Radarr.Api.V3/ProviderControllerBase.cs +++ b/src/Radarr.Api.V3/ProviderControllerBase.cs @@ -33,7 +33,7 @@ namespace Radarr.Api.V3 PostValidator.RuleFor(c => c.Fields).NotNull(); } - public override TProviderResource GetResourceById(int id) + protected override TProviderResource GetResourceById(int id) { var definition = _providerFactory.Get(id); _providerFactory.SetProviderCharacteristics(definition); diff --git a/src/Radarr.Api.V3/Qualities/QualityDefinitionController.cs b/src/Radarr.Api.V3/Qualities/QualityDefinitionController.cs index f8b59491c..37ca3f0b0 100644 --- a/src/Radarr.Api.V3/Qualities/QualityDefinitionController.cs +++ b/src/Radarr.Api.V3/Qualities/QualityDefinitionController.cs @@ -26,7 +26,7 @@ namespace Radarr.Api.V3.Qualities return Accepted(model.Id); } - public override QualityDefinitionResource GetResourceById(int id) + protected override QualityDefinitionResource GetResourceById(int id) { return _qualityDefinitionService.GetById(id).ToResource(); } diff --git a/src/Radarr.Api.V3/Queue/QueueController.cs b/src/Radarr.Api.V3/Queue/QueueController.cs index 0fe115268..0d5544249 100644 --- a/src/Radarr.Api.V3/Queue/QueueController.cs +++ b/src/Radarr.Api.V3/Queue/QueueController.cs @@ -54,7 +54,7 @@ namespace Radarr.Api.V3.Queue _qualityComparer = new QualityModelComparer(qualityProfileService.GetDefaultProfile(string.Empty)); } - public override QueueResource GetResourceById(int id) + protected override QueueResource GetResourceById(int id) { throw new NotImplementedException(); } diff --git a/src/Radarr.Api.V3/Queue/QueueDetailsController.cs b/src/Radarr.Api.V3/Queue/QueueDetailsController.cs index 786fed3fd..500bf3629 100644 --- a/src/Radarr.Api.V3/Queue/QueueDetailsController.cs +++ b/src/Radarr.Api.V3/Queue/QueueDetailsController.cs @@ -26,7 +26,7 @@ namespace Radarr.Api.V3.Queue _pendingReleaseService = pendingReleaseService; } - public override QueueResource GetResourceById(int id) + protected override QueueResource GetResourceById(int id) { throw new NotImplementedException(); } diff --git a/src/Radarr.Api.V3/Queue/QueueStatusController.cs b/src/Radarr.Api.V3/Queue/QueueStatusController.cs index 3b73a75a1..ec0cf9bd9 100644 --- a/src/Radarr.Api.V3/Queue/QueueStatusController.cs +++ b/src/Radarr.Api.V3/Queue/QueueStatusController.cs @@ -30,7 +30,7 @@ namespace Radarr.Api.V3.Queue _broadcastDebounce = new Debouncer(BroadcastChange, TimeSpan.FromSeconds(5)); } - public override QueueStatusResource GetResourceById(int id) + protected override QueueStatusResource GetResourceById(int id) { throw new NotImplementedException(); } diff --git a/src/Radarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs b/src/Radarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs index 061646c01..bc9e7f758 100644 --- a/src/Radarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs +++ b/src/Radarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs @@ -34,7 +34,7 @@ namespace Radarr.Api.V3.RemotePathMappings .SetValidator(pathExistsValidator); } - public override RemotePathMappingResource GetResourceById(int id) + protected override RemotePathMappingResource GetResourceById(int id) { return _remotePathMappingService.Get(id).ToResource(); } diff --git a/src/Radarr.Api.V3/Restrictions/RestrictionController.cs b/src/Radarr.Api.V3/Restrictions/RestrictionController.cs index 930ddcc94..b71ad3836 100644 --- a/src/Radarr.Api.V3/Restrictions/RestrictionController.cs +++ b/src/Radarr.Api.V3/Restrictions/RestrictionController.cs @@ -27,7 +27,7 @@ namespace Radarr.Api.V3.Restrictions }); } - public override RestrictionResource GetResourceById(int id) + protected override RestrictionResource GetResourceById(int id) { return _restrictionService.Get(id).ToResource(); } diff --git a/src/Radarr.Api.V3/RootFolders/RootFolderController.cs b/src/Radarr.Api.V3/RootFolders/RootFolderController.cs index dcc76f93c..d3be17883 100644 --- a/src/Radarr.Api.V3/RootFolders/RootFolderController.cs +++ b/src/Radarr.Api.V3/RootFolders/RootFolderController.cs @@ -41,7 +41,7 @@ namespace Radarr.Api.V3.RootFolders .SetValidator(folderWritableValidator); } - public override RootFolderResource GetResourceById(int id) + protected override RootFolderResource GetResourceById(int id) { var timeout = Request?.GetBooleanQueryParameter("timeout", true) ?? true; diff --git a/src/Radarr.Api.V3/System/Tasks/TaskController.cs b/src/Radarr.Api.V3/System/Tasks/TaskController.cs index 3a46212ab..1a8fc12ce 100644 --- a/src/Radarr.Api.V3/System/Tasks/TaskController.cs +++ b/src/Radarr.Api.V3/System/Tasks/TaskController.cs @@ -31,7 +31,7 @@ namespace Radarr.Api.V3.System.Tasks .ToList(); } - public override TaskResource GetResourceById(int id) + protected override TaskResource GetResourceById(int id) { var task = _taskManager.GetAll() .SingleOrDefault(t => t.Id == id); diff --git a/src/Radarr.Api.V3/Tags/TagController.cs b/src/Radarr.Api.V3/Tags/TagController.cs index 716f3e48f..f522bcfe2 100644 --- a/src/Radarr.Api.V3/Tags/TagController.cs +++ b/src/Radarr.Api.V3/Tags/TagController.cs @@ -22,7 +22,7 @@ namespace Radarr.Api.V3.Tags _tagService = tagService; } - public override TagResource GetResourceById(int id) + protected override TagResource GetResourceById(int id) { return _tagService.GetTag(id).ToResource(); } diff --git a/src/Radarr.Api.V3/Tags/TagDetailsController.cs b/src/Radarr.Api.V3/Tags/TagDetailsController.cs index 469f185cb..466b3f4f3 100644 --- a/src/Radarr.Api.V3/Tags/TagDetailsController.cs +++ b/src/Radarr.Api.V3/Tags/TagDetailsController.cs @@ -16,7 +16,7 @@ namespace Radarr.Api.V3.Tags _tagService = tagService; } - public override TagDetailsResource GetResourceById(int id) + protected override TagDetailsResource GetResourceById(int id) { return _tagService.Details(id).ToResource(); } diff --git a/src/Radarr.Http/ErrorManagement/RadarrErrorPipeline.cs b/src/Radarr.Http/ErrorManagement/RadarrErrorPipeline.cs index 3266d25d9..b4ce151aa 100644 --- a/src/Radarr.Http/ErrorManagement/RadarrErrorPipeline.cs +++ b/src/Radarr.Http/ErrorManagement/RadarrErrorPipeline.cs @@ -29,22 +29,17 @@ namespace Radarr.Http.ErrorManagement var exceptionHandlerPathFeature = context.Features.Get(); var exception = exceptionHandlerPathFeature?.Error; - _logger.Warn(exception); - var statusCode = HttpStatusCode.InternalServerError; var errorModel = new ErrorModel { - Message = exception.Message, - Description = exception.ToString() + Message = exception?.Message, + Description = exception?.ToString() }; if (exception is ApiException apiException) { _logger.Warn(apiException, "API Error:\n{0}", apiException.Message); - /* var body = RequestStream.FromStream(context.Request.Body).AsString(); - _logger.Trace("Request body:\n{0}", body);*/ - errorModel = new ErrorModel(apiException); statusCode = apiException.StatusCode; } @@ -59,30 +54,14 @@ namespace Radarr.Http.ErrorManagement } else if (exception is NzbDroneClientException clientException) { - errorModel = new ErrorModel - { - Message = exception.Message, - Description = exception.ToString() - }; statusCode = clientException.StatusCode; } - else if (exception is ModelNotFoundException notFoundException) + else if (exception is ModelNotFoundException) { - errorModel = new ErrorModel - { - Message = exception.Message, - Description = exception.ToString() - }; statusCode = HttpStatusCode.NotFound; } - else if (exception is ModelConflictException conflictException) + else if (exception is ModelConflictException) { - _logger.Error(exception, "DB error"); - errorModel = new ErrorModel - { - Message = exception.Message, - Description = exception.ToString() - }; statusCode = HttpStatusCode.Conflict; } else if (exception is SQLiteException sqLiteException) @@ -91,18 +70,16 @@ namespace Radarr.Http.ErrorManagement { if (sqLiteException.Message.Contains("constraint failed")) { - errorModel = new ErrorModel - { - Message = exception.Message, - }; statusCode = HttpStatusCode.Conflict; } } _logger.Error(sqLiteException, "[{0} {1}]", context.Request.Method, context.Request.Path); } - - _logger.Fatal(exception, "Request Failed. {0} {1}", context.Request.Method, context.Request.Path); + else + { + _logger.Fatal(exception, "Request Failed. {0} {1}", context.Request.Method, context.Request.Path); + } await errorModel.WriteToResponse(response, statusCode); } diff --git a/src/Radarr.Http/REST/RestController.cs b/src/Radarr.Http/REST/RestController.cs index cc5922b0e..848c06954 100644 --- a/src/Radarr.Http/REST/RestController.cs +++ b/src/Radarr.Http/REST/RestController.cs @@ -39,7 +39,19 @@ namespace Radarr.Http.REST } [RestGetById] - public abstract TResource GetResourceById(int id); + public ActionResult GetResourceByIdWithErrorHandler(int id) + { + try + { + return GetResourceById(id); + } + catch (ModelNotFoundException) + { + return NotFound(); + } + } + + protected abstract TResource GetResourceById(int id); public override void OnActionExecuting(ActionExecutingContext context) { @@ -73,19 +85,6 @@ namespace Radarr.Http.REST base.OnActionExecuting(context); } - public override void OnActionExecuted(ActionExecutedContext context) - { - var descriptor = context.ActionDescriptor as ControllerActionDescriptor; - - var attributes = descriptor.MethodInfo.CustomAttributes; - - if (context.Exception?.GetType() == typeof(ModelNotFoundException) && - attributes.Any(x => x.AttributeType == typeof(RestGetByIdAttribute))) - { - context.Result = new NotFoundResult(); - } - } - protected void ValidateResource(TResource resource, bool skipValidate = false, bool skipSharedValidate = false) { if (resource == null) @@ -118,13 +117,13 @@ namespace Radarr.Http.REST protected ActionResult Accepted(int id) { var result = GetResourceById(id); - return AcceptedAtAction(nameof(GetResourceById), new { id = id }, result); + return AcceptedAtAction(nameof(GetResourceByIdWithErrorHandler), new { id = id }, result); } protected ActionResult Created(int id) { var result = GetResourceById(id); - return CreatedAtAction(nameof(GetResourceById), new { id = id }, result); + return CreatedAtAction(nameof(GetResourceByIdWithErrorHandler), new { id = id }, result); } } }