From b29258676466782d2333ba321db70cbaede4a4d1 Mon Sep 17 00:00:00 2001 From: eee4 <41441600+eee4@users.noreply.github.com> Date: Mon, 21 Jul 2025 14:29:26 +0200 Subject: [PATCH] fix: handle requests with a non-integer list for category_id --- Controllers/QuoteController.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Controllers/QuoteController.cs b/Controllers/QuoteController.cs index 2a85bed..2d83a00 100644 --- a/Controllers/QuoteController.cs +++ b/Controllers/QuoteController.cs @@ -54,10 +54,21 @@ public class QuotesController : ControllerBase var totalQuotes = await _db.Quotes.CountAsync(); const int PageSize = 10; - List? categories = category_id? - .Split(",") - .Select(Int32.Parse) - .ToList(); + List? categories; + try + { + categories = category_id? + .Split(",") + .Select(Int32.Parse) + .ToList(); + } catch + { + // Try to catch badly formatted requests + return BadRequest(new ErrorDTO { + Status = "error", + Error_msg = "Category_id can be either an integer, or comma separated integers" + }); + } if (page_no <= 0) {