diff --git a/Shoko.Server/API/v3/Controllers/FilterController.cs b/Shoko.Server/API/v3/Controllers/FilterController.cs index 50e8bda73..27866c3c0 100644 --- a/Shoko.Server/API/v3/Controllers/FilterController.cs +++ b/Shoko.Server/API/v3/Controllers/FilterController.cs @@ -82,12 +82,22 @@ [FromQuery] [Range(1, int.MaxValue)] int page = 1, [FromQuery] bool withConditio [HttpPost] public ActionResult AddNewFilter(Filter.Input.CreateOrUpdateFilterBody body) { - var filterPreset = new FilterPreset { FilterType = GroupFilterType.UserDefined }; - var filter = _factory.MergeWithExisting(body, filterPreset, ModelState); - if (!ModelState.IsValid) - return ValidationProblem(ModelState); + try + { + var filterPreset = new FilterPreset + { + FilterType = GroupFilterType.UserDefined + }; + var filter = _factory.MergeWithExisting(body, filterPreset, ModelState); + if (!ModelState.IsValid) + return ValidationProblem(ModelState); - return filter; + return filter; + } + catch (ArgumentException e) + { + return ValidationProblem(e.Message, "Expression"); + } } /// @@ -222,16 +232,23 @@ public ActionResult PatchFilter([FromRoute] int filterID, JsonPatchDocum if (filterPreset == null) return NotFound(FilterNotFound); - var body = _factory.CreateOrUpdateFilterBody(filterPreset); - document.ApplyTo(body, ModelState); - if (!ModelState.IsValid) - return ValidationProblem(ModelState); - - var filter = _factory.MergeWithExisting(body, filterPreset, ModelState); - if (!ModelState.IsValid) - return ValidationProblem(ModelState); - - return filter; + try + { + var body = _factory.CreateOrUpdateFilterBody(filterPreset); + document.ApplyTo(body, ModelState); + if (!ModelState.IsValid) + return ValidationProblem(ModelState); + + var filter = _factory.MergeWithExisting(body, filterPreset, ModelState); + if (!ModelState.IsValid) + return ValidationProblem(ModelState); + + return filter; + } + catch (ArgumentException e) + { + return ValidationProblem(e.Message, "Expression"); + } } /// @@ -248,11 +265,18 @@ public ActionResult PutFilter([FromRoute] int filterID, Filter.Input.Cre if (filterPreset == null) return NotFound(FilterNotFound); - var filter = _factory.MergeWithExisting(body, filterPreset, ModelState); - if (!ModelState.IsValid) - return ValidationProblem(ModelState); + try + { + var filter = _factory.MergeWithExisting(body, filterPreset, ModelState); + if (!ModelState.IsValid) + return ValidationProblem(ModelState); - return filter; + return filter; + } + catch (ArgumentException e) + { + return ValidationProblem(e.Message, "Expression"); + } } ///