fix: handle requests with a non-integer list for category_id

This commit is contained in:
2025-07-21 14:29:26 +02:00
parent 779772e60c
commit b292586764

View File

@@ -54,10 +54,21 @@ public class QuotesController : ControllerBase
var totalQuotes = await _db.Quotes.CountAsync();
const int PageSize = 10;
List<int>? categories = category_id?
.Split(",")
.Select(Int32.Parse)
.ToList();
List<int>? 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)
{