pdevito3 / QueryKit

🎛️ QueryKit is a .NET library that makes it easier to query your data by providing a fluent and intuitive syntax for filtering and sorting.
Apache License 2.0
152 stars 13 forks source link

Add base exception to allow for easier error catching #25

Closed jthomperoo closed 6 months ago

jthomperoo commented 7 months ago

Hi, thanks for this project, it's a great tool!

It would be nice if instead of having to catch each exception QueryKit can throw individually there was a base exception which could be caught.

So instead of this:

try {
    var filterInput = """FirstName == "Jane" && Age > 10""";
    var people = _dbContext.People
        .ApplyQueryKitFilter(filterInput)
        .ToList();
}
catch (ParsingException ex)
{
    // Handle exception
}
catch (UnknownFilterPropertyException ex)
{
    // Handle exception
}
catch (SortParsingException ex)
{
    // Handle exception
}
catch (QueryKitDbContextTypeException ex)
{
    // Handle exception
}
catch (SoundsLikeNotImplementedException ex)
{
    // Handle exception
}
catch (QueryKitParsingException ex)
{
    // Handle exception
}

We could do this:

try {
    var filterInput = """FirstName == "Jane" && Age > 10""";
    var people = _dbContext.People
        .ApplyQueryKitFilter(filterInput)
        .ToList();
}
catch (QueryKitException ex)
{
    // Handle exception
}

This still allows for more fine grained error handling if needed in the same way as before, but just for the use case where a failed filter is handled the same way for all scenarios it's a bit easier.