I am throwing custom exceptions inside my resolvers, but they are being caught and wrapped by Automapper so we cant handle them elsewhere in the program. I've included a simple example of the problem, the desired outcome is to catch an InterfaceError but it only catches an AutoMapperException with the InterfaceError as an inner exception.
In class:
public Order MapOrder(InterfaceOrder iOrder)
{
try
{
Order mappedOrder = Mapper.Map<InterfaceOrder, Order>(iOrder);
}
catch (InterfaceException ex)
{
Log("Interface error");
}
catch (Exception ex)
{
Log("error");
}
return mappedOrder;
}
Mapping:
Mapper.CreateMap<InterfaceOrder, Order>()
.ForMember(c => c.Name, op => op.ResolveUsing(data =>
{
if (Name.Length > 50)
{
throw new InterfaceException("Error!", ex);
}
else
{
return c.Name
}
}));