diff --git a/QueryKit/Exceptions/FilterParsingException.cs b/QueryKit/Exceptions/ParsingException.cs similarity index 84% rename from QueryKit/Exceptions/FilterParsingException.cs rename to QueryKit/Exceptions/ParsingException.cs index 5220c63..d6a77fc 100644 --- a/QueryKit/Exceptions/FilterParsingException.cs +++ b/QueryKit/Exceptions/ParsingException.cs @@ -2,7 +2,7 @@ namespace QueryKit.Exceptions; public sealed class ParsingException : Exception { - public ParsingException(Exception exception) + public ParsingException(Exception exception) : 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) { } diff --git a/QueryKit/Exceptions/QueryKitDbContextTypeException.cs b/QueryKit/Exceptions/QueryKitDbContextTypeException.cs index 9954fc2..eb92550 100644 --- a/QueryKit/Exceptions/QueryKitDbContextTypeException.cs +++ b/QueryKit/Exceptions/QueryKitDbContextTypeException.cs @@ -1,8 +1,8 @@ namespace QueryKit.Exceptions; -public sealed class QueryKitDbContextTypeException : Exception +public sealed class QueryKitDbContextTypeException : QueryKitException { - public QueryKitDbContextTypeException(string specificMessage) + public QueryKitDbContextTypeException(string specificMessage) : base($"There no DbContext type provided in your QueryKit config, but one was needed for this operation. {specificMessage}") { } diff --git a/QueryKit/Exceptions/QueryKitException.cs b/QueryKit/Exceptions/QueryKitException.cs new file mode 100644 index 0000000..c5a4fff --- /dev/null +++ b/QueryKit/Exceptions/QueryKitException.cs @@ -0,0 +1,10 @@ +namespace QueryKit.Exceptions; + +/// +/// Base QueryKit exception, all exceptions thrown by QueryKit inherit this. +/// +public class QueryKitException : Exception +{ + public QueryKitException(string message, Exception exception) : base(message, exception) {} + public QueryKitException(string message) : base(message) {} +} diff --git a/QueryKit/Exceptions/QueryKitParsingException.cs b/QueryKit/Exceptions/QueryKitParsingException.cs index 4318ee1..a00049f 100644 --- a/QueryKit/Exceptions/QueryKitParsingException.cs +++ b/QueryKit/Exceptions/QueryKitParsingException.cs @@ -1,8 +1,8 @@ namespace QueryKit.Exceptions; -public sealed class QueryKitParsingException : Exception +public sealed class QueryKitParsingException : QueryKitException { - public QueryKitParsingException(string message) + public QueryKitParsingException(string message) : base(message) { } diff --git a/QueryKit/Exceptions/SortParsingException.cs b/QueryKit/Exceptions/SortParsingException.cs index a20c6fd..d104ec9 100644 --- a/QueryKit/Exceptions/SortParsingException.cs +++ b/QueryKit/Exceptions/SortParsingException.cs @@ -1,8 +1,8 @@ namespace QueryKit.Exceptions; -public sealed class SortParsingException : Exception +public sealed class SortParsingException : QueryKitException { - public SortParsingException(string propertyName) + public SortParsingException(string propertyName) : base($"Parsing failed during sorting. '{propertyName}' was not recognized.") { } diff --git a/QueryKit/Exceptions/SoundsLikeNotImplementedException.cs b/QueryKit/Exceptions/SoundsLikeNotImplementedException.cs index 6689a18..44e035a 100644 --- a/QueryKit/Exceptions/SoundsLikeNotImplementedException.cs +++ b/QueryKit/Exceptions/SoundsLikeNotImplementedException.cs @@ -1,8 +1,8 @@ namespace QueryKit.Exceptions; -public sealed class SoundsLikeNotImplementedException : Exception +public sealed class SoundsLikeNotImplementedException : QueryKitException { - public SoundsLikeNotImplementedException(string dbContextType) + public SoundsLikeNotImplementedException(string dbContextType) : base($"The DbContext type {dbContextType} does not have a SoundsLike method.") { } diff --git a/QueryKit/Exceptions/UnknownFilterPropertyException.cs b/QueryKit/Exceptions/UnknownFilterPropertyException.cs index c6025e5..0a75fb0 100644 --- a/QueryKit/Exceptions/UnknownFilterPropertyException.cs +++ b/QueryKit/Exceptions/UnknownFilterPropertyException.cs @@ -1,8 +1,8 @@ namespace QueryKit.Exceptions; -public sealed class UnknownFilterPropertyException : Exception +public sealed class UnknownFilterPropertyException : QueryKitException { - public UnknownFilterPropertyException(string propertyName) + public UnknownFilterPropertyException(string propertyName) : base($"The filter property '{propertyName}' was not recognized.") { } diff --git a/README.md b/README.md index 8e71f0d..b9acb58 100644 --- a/README.md +++ b/README.md @@ -419,7 +419,9 @@ var people = _dbContext.People If you want to capture errors to easily throw a `400`, you can add error handling around these exceptions: -* 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). +* A `QueryKitException` is the base class for all of the exceptions listed below. This can be caught to catch +any exception thrown by QueryKit. +* 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). * An `UnknownFilterPropertyException` will be thrown if a property is not recognized during filtering * A `SortParsingException` will be thrown if a property or operation is not recognized during sorting * 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(); ``` ## Community Projects -- [Fluent QueryKit](https://github.com/CLFPosthumus/fluent-querykit) for easy usage in javascript or typescript projects. \ No newline at end of file +- [Fluent QueryKit](https://github.com/CLFPosthumus/fluent-querykit) for easy usage in javascript or typescript projects.