From 7f4636326d312333f750617c647c7515c8637d59 Mon Sep 17 00:00:00 2001 From: Matt Winston Date: Mon, 2 Feb 2026 13:12:12 -0500 Subject: [PATCH] Adding an error catch and logging for the failing ComponentQuestionList endpoint --- .../Question/ComponentQuestionBusiness.cs | 2 +- .../Controllers/QuestionsController.cs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CSETWebApi/CSETWeb_Api/CSETWebCore.Business/Question/ComponentQuestionBusiness.cs b/CSETWebApi/CSETWeb_Api/CSETWebCore.Business/Question/ComponentQuestionBusiness.cs index 3a07421b9b..6df5860e9b 100644 --- a/CSETWebApi/CSETWeb_Api/CSETWebCore.Business/Question/ComponentQuestionBusiness.cs +++ b/CSETWebApi/CSETWeb_Api/CSETWebCore.Business/Question/ComponentQuestionBusiness.cs @@ -202,7 +202,7 @@ public async Task GetResponseAsync() _subCatAnswersByHeadingId = SubCatAnswers .Where(x => x.HeadingId > 0) .GroupBy(x => x.HeadingId) - .ToDictionary(g => g.Key, g => g.First()); + .ToDictionary(g => g.Key, g => g.FirstOrDefault()); } AddResponse(resp, list2, "Component Defaults"); diff --git a/CSETWebApi/CSETWeb_Api/CSETWeb_ApiCore/Controllers/QuestionsController.cs b/CSETWebApi/CSETWeb_Api/CSETWeb_ApiCore/Controllers/QuestionsController.cs index 04ce2af599..d31636bfdd 100644 --- a/CSETWebApi/CSETWeb_Api/CSETWeb_ApiCore/Controllers/QuestionsController.cs +++ b/CSETWebApi/CSETWeb_Api/CSETWeb_ApiCore/Controllers/QuestionsController.cs @@ -116,10 +116,19 @@ public IActionResult GetList([FromQuery] string group) [Route("api/ComponentQuestionList")] public async Task GetComponentQuestionsList() { - var manager = new ComponentQuestionBusiness(_context, _assessmentUtil, _token, _questionRequirement); - QuestionResponse resp = await manager.GetResponseAsync(); + try + { + var manager = new ComponentQuestionBusiness(_context, _assessmentUtil, _token, _questionRequirement); + QuestionResponse resp = await manager.GetResponseAsync(); + + return Ok(resp); + } + catch (Exception exc) + { + LogManager.GetCurrentClassLogger().Error(exc); + return BadRequest(exc.Message); + } - return Ok(resp); }