mirror of
https://github.com/Biarity/Sieve.git
synced 2024-11-22 13:32:33 +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.ComponentModel;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using Sieve.Exceptions;
|
||||||
|
|
||||||
namespace Sieve.Services
|
namespace Sieve.Services
|
||||||
{
|
{
|
||||||
@ -294,7 +295,6 @@ namespace Sieve.Services
|
|||||||
result = customMethod.Invoke(parent, parameters)
|
result = customMethod.Invoke(parent, parameters)
|
||||||
as IQueryable<TEntity>;
|
as IQueryable<TEntity>;
|
||||||
}
|
}
|
||||||
catch (ArgumentException) { } // name matched with custom emthod for a differnt type
|
|
||||||
catch (TargetParameterCountException)
|
catch (TargetParameterCountException)
|
||||||
{
|
{
|
||||||
if (optionalParameters != null)
|
if (optionalParameters != null)
|
||||||
@ -307,6 +307,18 @@ namespace Sieve.Services
|
|||||||
throw;
|
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;
|
return result;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Sieve</id>
|
<id>Sieve</id>
|
||||||
<version>1.3.9</version>
|
<version>1.3.91</version>
|
||||||
<title>Sieve</title>
|
<title>Sieve</title>
|
||||||
<authors>Biarity</authors>
|
<authors>Biarity</authors>
|
||||||
<owners>Biarity</owners>
|
<owners>Biarity</owners>
|
||||||
@ -13,7 +13,7 @@
|
|||||||
<description>
|
<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/
|
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>
|
</description>
|
||||||
<releaseNotes>Fluent API v1 and case-insensitive operators</releaseNotes>
|
<releaseNotes>Custom method case-insensitivity</releaseNotes>
|
||||||
<copyright>Copyright 2018</copyright>
|
<copyright>Copyright 2018</copyright>
|
||||||
<tags>aspnetcore filter sort page paginate sieve search</tags>
|
<tags>aspnetcore filter sort page paginate sieve search</tags>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
Loading…
Reference in New Issue
Block a user