Skip to content

Commit cf90d9a

Browse files
authored
Merge pull request #26 from jthomperoo/25_add_base_query_kit_exception
feat: add base QueryKitException
2 parents 79dc08e + e4fae58 commit cf90d9a

8 files changed

+25
-13
lines changed

QueryKit/Exceptions/FilterParsingException.cs renamed to QueryKit/Exceptions/ParsingException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace QueryKit.Exceptions;
22

33
public sealed class ParsingException : Exception
44
{
5-
public ParsingException(Exception exception)
5+
public ParsingException(Exception exception)
66
: base($"There was a parsing failure, likely due to an invalid comparison or logical operator. You may also be missing double quotes surrounding a string or guid.", exception)
77
{
88
}

QueryKit/Exceptions/QueryKitDbContextTypeException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace QueryKit.Exceptions;
22

3-
public sealed class QueryKitDbContextTypeException : Exception
3+
public sealed class QueryKitDbContextTypeException : QueryKitException
44
{
5-
public QueryKitDbContextTypeException(string specificMessage)
5+
public QueryKitDbContextTypeException(string specificMessage)
66
: base($"There no DbContext type provided in your QueryKit config, but one was needed for this operation. {specificMessage}")
77
{
88
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace QueryKit.Exceptions;
2+
3+
/// <summary>
4+
/// Base QueryKit exception, all exceptions thrown by QueryKit inherit this.
5+
/// </summary>
6+
public class QueryKitException : Exception
7+
{
8+
public QueryKitException(string message, Exception exception) : base(message, exception) {}
9+
public QueryKitException(string message) : base(message) {}
10+
}

QueryKit/Exceptions/QueryKitParsingException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace QueryKit.Exceptions;
22

3-
public sealed class QueryKitParsingException : Exception
3+
public sealed class QueryKitParsingException : QueryKitException
44
{
5-
public QueryKitParsingException(string message)
5+
public QueryKitParsingException(string message)
66
: base(message)
77
{
88
}

QueryKit/Exceptions/SortParsingException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace QueryKit.Exceptions;
22

3-
public sealed class SortParsingException : Exception
3+
public sealed class SortParsingException : QueryKitException
44
{
5-
public SortParsingException(string propertyName)
5+
public SortParsingException(string propertyName)
66
: base($"Parsing failed during sorting. '{propertyName}' was not recognized.")
77
{
88
}

QueryKit/Exceptions/SoundsLikeNotImplementedException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace QueryKit.Exceptions;
22

3-
public sealed class SoundsLikeNotImplementedException : Exception
3+
public sealed class SoundsLikeNotImplementedException : QueryKitException
44
{
5-
public SoundsLikeNotImplementedException(string dbContextType)
5+
public SoundsLikeNotImplementedException(string dbContextType)
66
: base($"The DbContext type {dbContextType} does not have a SoundsLike method.")
77
{
88
}

QueryKit/Exceptions/UnknownFilterPropertyException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace QueryKit.Exceptions;
22

3-
public sealed class UnknownFilterPropertyException : Exception
3+
public sealed class UnknownFilterPropertyException : QueryKitException
44
{
5-
public UnknownFilterPropertyException(string propertyName)
5+
public UnknownFilterPropertyException(string propertyName)
66
: base($"The filter property '{propertyName}' was not recognized.")
77
{
88
}

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ var people = _dbContext.People
419419
420420
If you want to capture errors to easily throw a `400`, you can add error handling around these exceptions:
421421
422-
* A `FilterParsingException` will be thrown when there is an invalid operator or bad syntax is used (e.g. not using double quotes around a string or guid).
422+
* A `QueryKitException` is the base class for all of the exceptions listed below. This can be caught to catch
423+
any exception thrown by QueryKit.
424+
* A `ParsingException` will be thrown when there is an invalid operator or bad syntax is used (e.g. not using double quotes around a string or guid).
423425
* An `UnknownFilterPropertyException` will be thrown if a property is not recognized during filtering
424426
* A `SortParsingException` will be thrown if a property or operation is not recognized during sorting
425427
* A `QueryKitDbContextTypeException` will be thrown when trying to use a `DbContext` specific workflow without passing that context (e.g. SoundEx)
@@ -477,4 +479,4 @@ var people = await appliedQueryable.ToListAsync();
477479
```
478480
479481
## Community Projects
480-
- [Fluent QueryKit](https://github.com/CLFPosthumus/fluent-querykit) for easy usage in javascript or typescript projects.
482+
- [Fluent QueryKit](https://github.com/CLFPosthumus/fluent-querykit) for easy usage in javascript or typescript projects.

0 commit comments

Comments
 (0)