Handle all possible exceptions using SieveExceptions (#11)

This commit is contained in:
Biarity 2018-02-15 18:53:09 +10:00
parent 6d3fedf9f5
commit 67606e281b
2 changed files with 130 additions and 96 deletions

View File

@ -5,6 +5,13 @@ using System.Text;
namespace Sieve.Exceptions namespace Sieve.Exceptions
{ {
public class SieveException : Exception public class SieveException : Exception
{
public SieveException(string message) : base(message)
{
}
public SieveException(string message, Exception innerException) : base(message, innerException)
{ {
} }
} }
}

View File

@ -97,6 +97,8 @@ namespace Sieve.Services
ISieveModel<IFilterTerm, ISortTerm> model, ISieveModel<IFilterTerm, ISortTerm> model,
IQueryable<TEntity> result, IQueryable<TEntity> result,
object[] dataForCustomMethods = null) object[] dataForCustomMethods = null)
{
try
{ {
if (model?.FiltersParsed == null) if (model?.FiltersParsed == null)
return result; return result;
@ -183,6 +185,13 @@ namespace Sieve.Services
return result; return result;
} }
catch (Exception ex)
{
if (ex is SieveException)
throw;
throw new SieveException(ex.Message, ex);
}
}
/// <summary> /// <summary>
/// Apply sorting parameters found in `model` to `source` /// Apply sorting parameters found in `model` to `source`
@ -196,6 +205,8 @@ namespace Sieve.Services
ISieveModel<IFilterTerm, ISortTerm> model, ISieveModel<IFilterTerm, ISortTerm> model,
IQueryable<TEntity> result, IQueryable<TEntity> result,
object[] dataForCustomMethods = null) object[] dataForCustomMethods = null)
{
try
{ {
if (model?.SortsParsed == null) if (model?.SortsParsed == null)
return result; return result;
@ -224,6 +235,13 @@ namespace Sieve.Services
return result; return result;
} }
catch (Exception ex)
{
if (ex is SieveException)
throw;
throw new SieveException(ex.Message, ex);
}
}
/// <summary> /// <summary>
/// Apply pagination parameters found in `model` to `source` /// Apply pagination parameters found in `model` to `source`
@ -236,6 +254,8 @@ namespace Sieve.Services
public IQueryable<TEntity> ApplyPagination<TEntity>( public IQueryable<TEntity> ApplyPagination<TEntity>(
ISieveModel<IFilterTerm, ISortTerm> model, ISieveModel<IFilterTerm, ISortTerm> model,
IQueryable<TEntity> result) IQueryable<TEntity> result)
{
try
{ {
var page = model?.Page ?? 1; var page = model?.Page ?? 1;
var pageSize = model?.PageSize ?? _options.Value.DefaultPageSize; var pageSize = model?.PageSize ?? _options.Value.DefaultPageSize;
@ -248,6 +268,13 @@ namespace Sieve.Services
return result; return result;
} }
catch (Exception ex)
{
if (ex is SieveException)
throw;
throw new SieveException(ex.Message, ex);
}
}
protected virtual SievePropertyMapper MapProperties(SievePropertyMapper mapper) protected virtual SievePropertyMapper MapProperties(SievePropertyMapper mapper)