mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-22 05:22:57 +01:00
Basic exception handling (#7)
This commit is contained in:
parent
9d0ef79595
commit
b625d15cb8
39
Sieve/Exceptions/SieveIncompatibleMethodException.cs
Normal file
39
Sieve/Exceptions/SieveIncompatibleMethodException.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sieve.Exceptions
|
||||
{
|
||||
public class SieveIncompatibleMethodException : Exception
|
||||
{
|
||||
public string MethodName { get; protected set; }
|
||||
public Type ExpectedType { get; protected set; }
|
||||
public Type ActualType { get; protected set; }
|
||||
|
||||
|
||||
public SieveIncompatibleMethodException(
|
||||
string methodName,
|
||||
Type expectedType,
|
||||
Type actualType,
|
||||
string message)
|
||||
: base(message)
|
||||
{
|
||||
MethodName = methodName;
|
||||
ExpectedType = expectedType;
|
||||
ActualType = actualType;
|
||||
}
|
||||
|
||||
public SieveIncompatibleMethodException(
|
||||
string methodName,
|
||||
Type expectedType,
|
||||
Type actualType,
|
||||
string message,
|
||||
Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
MethodName = methodName;
|
||||
ExpectedType = expectedType;
|
||||
ActualType = actualType;
|
||||
}
|
||||
}
|
||||
}
|
21
Sieve/Exceptions/SieveMethodNotFoundException.cs
Normal file
21
Sieve/Exceptions/SieveMethodNotFoundException.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sieve.Exceptions
|
||||
{
|
||||
public class SieveMethodNotFoundException : Exception
|
||||
{
|
||||
public string MethodName { get; protected set; }
|
||||
|
||||
public SieveMethodNotFoundException(string methodName, string message) : base (message)
|
||||
{
|
||||
MethodName = methodName;
|
||||
}
|
||||
|
||||
public SieveMethodNotFoundException(string methodName, string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
MethodName = methodName;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ using Sieve.Extensions;
|
||||
using System.ComponentModel;
|
||||
using System.Collections;
|
||||
using System.Linq.Expressions;
|
||||
using Sieve.Exceptions;
|
||||
|
||||
namespace Sieve.Services
|
||||
{
|
||||
@ -294,7 +295,6 @@ namespace Sieve.Services
|
||||
result = customMethod.Invoke(parent, parameters)
|
||||
as IQueryable<TEntity>;
|
||||
}
|
||||
catch (ArgumentException) { } // name matched with custom emthod for a differnt type
|
||||
catch (TargetParameterCountException)
|
||||
{
|
||||
if (optionalParameters != null)
|
||||
@ -307,6 +307,18 @@ namespace Sieve.Services
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (ArgumentException) // name matched with custom method for a differnt type
|
||||
{
|
||||
var expected = typeof(TEntity);
|
||||
var actual = ((IQueryable)customMethod.ReturnParameter).ElementType;
|
||||
throw new SieveIncompatibleMethodException(name, expected, actual,
|
||||
$"{name} failed. Expected a custom method for type {expected} but only found for type {actual}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SieveMethodNotFoundException(name,
|
||||
$"{name} not found.");
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -2,7 +2,7 @@
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Sieve</id>
|
||||
<version>1.3.9</version>
|
||||
<version>1.3.91</version>
|
||||
<title>Sieve</title>
|
||||
<authors>Biarity</authors>
|
||||
<owners>Biarity</owners>
|
||||
@ -13,7 +13,7 @@
|
||||
<description>
|
||||
Sieve is a simple, clean, and extensible framework for .NET Core that adds sorting, filtering, and pagination functionality out of the box. Most common use case would be for serving ASP.NET Core GET queries. Documentation available on GitHub: https://github.com/Biarity/Sieve/
|
||||
</description>
|
||||
<releaseNotes>Fluent API v1 and case-insensitive operators</releaseNotes>
|
||||
<releaseNotes>Custom method case-insensitivity</releaseNotes>
|
||||
<copyright>Copyright 2018</copyright>
|
||||
<tags>aspnetcore filter sort page paginate sieve search</tags>
|
||||
<dependencies>
|
||||
|
Loading…
Reference in New Issue
Block a user