Added data to controller method exceptions, like Tapeti Flow does for yield point exceptions
Closes #25, stack traces seem fine in test scenarios
This commit is contained in:
parent
ce377810c8
commit
f4d008d6a9
@ -211,7 +211,7 @@ namespace Tapeti.Default
|
||||
private delegate Task MessageHandlerFunc(IControllerMessageContext context);
|
||||
|
||||
|
||||
private static MessageHandlerFunc WrapMethod(MethodInfo method, IEnumerable<ValueFactory> parameterFactories, ResultHandler resultHandler)
|
||||
private MessageHandlerFunc WrapMethod(MethodInfo method, IEnumerable<ValueFactory> parameterFactories, ResultHandler resultHandler)
|
||||
{
|
||||
if (resultHandler != null)
|
||||
return WrapResultHandlerMethod(method, parameterFactories, resultHandler);
|
||||
@ -229,49 +229,98 @@ namespace Tapeti.Default
|
||||
}
|
||||
|
||||
|
||||
private static MessageHandlerFunc WrapResultHandlerMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories, ResultHandler resultHandler)
|
||||
private MessageHandlerFunc WrapResultHandlerMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories, ResultHandler resultHandler)
|
||||
{
|
||||
return context =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = method.Invoke(context.Controller, parameterFactories.Select(p => p(context)).ToArray());
|
||||
return resultHandler(context, result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AddExceptionData(e);
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static MessageHandlerFunc WrapNullMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories)
|
||||
private MessageHandlerFunc WrapNullMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories)
|
||||
{
|
||||
return context =>
|
||||
{
|
||||
try
|
||||
{
|
||||
method.Invoke(context.Controller, parameterFactories.Select(p => p(context)).ToArray());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AddExceptionData(e);
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private static MessageHandlerFunc WrapTaskMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories)
|
||||
private MessageHandlerFunc WrapTaskMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories)
|
||||
{
|
||||
return context => (Task)method.Invoke(context.Controller, parameterFactories.Select(p => p(context)).ToArray());
|
||||
return context =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Task) method.Invoke(context.Controller, parameterFactories.Select(p => p(context)).ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AddExceptionData(e);
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private static MessageHandlerFunc WrapGenericTaskMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories)
|
||||
private MessageHandlerFunc WrapGenericTaskMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories)
|
||||
{
|
||||
return context =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Task<object>)method.Invoke(context.Controller, parameterFactories.Select(p => p(context)).ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AddExceptionData(e);
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private static MessageHandlerFunc WrapObjectMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories)
|
||||
private MessageHandlerFunc WrapObjectMethod(MethodBase method, IEnumerable<ValueFactory> parameterFactories)
|
||||
{
|
||||
return context =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return Task.FromResult(method.Invoke(context.Controller, parameterFactories.Select(p => p(context)).ToArray()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AddExceptionData(e);
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private void AddExceptionData(Exception exception)
|
||||
{
|
||||
exception.Data["Tapeti.Controller.Name"] = bindingInfo.ControllerType?.FullName;
|
||||
exception.Data["Tapeti.Controller.Method"] = bindingInfo.Method?.Name;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Contains information about the queue linked to the controller method.
|
||||
|
Loading…
Reference in New Issue
Block a user