public IActionResult Filter(string name) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var familyfilter = _familyRepository.Filter(name); if (familyfilter == null) { return(Content("The family is not found!")); } try { return(Ok(familyfilter)); } catch { return(BadRequest(ModelState)); //or you can throw new Exception } }