add not-found exception to handle on endpoint

This commit is contained in:
Developer 02
2025-08-03 09:31:36 +02:00
parent 1b9dac93a5
commit 6a4f8a12c7

View File

@@ -1,4 +1,5 @@
using MediatR;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Extensions.Options;
using System.DirectoryServices;
@@ -39,8 +40,9 @@ public class DirectorySearchQueryHandler(IOptions<ActiveDirectoryOptions> option
if (request.properties.Length > 0)
searcher.PropertiesToLoad.Clear();
searcher.PropertiesToLoad.AddRange([.. request.properties.Where(p => p is not null)]);
return searcher.FindAll().Cast<SearchResult>().Select(r => r.Properties);
searcher.PropertiesToLoad.AddRange(request.properties.Where(p => p is not null).ToArray());
var res = searcher.FindAll().Cast<SearchResult>().Select(r => r.Properties);
return res.Any() ? res : throw new NotFoundException();
});
}
}