I'd want to achieve something like this:
If exception was thrown in method that returns Json then return new Json(new { success = false, error = "unknown" });
but if method returns View
then return Redirect
public async Task Invoke(HttpContext ctx)
{
try
{
await next(ctx);
}
catch (Exception ex)
{
HandleException(ctx, ex);
}
}
private static void HandleException(HttpContext context, Exception ex)
{
// some logger
LoggerService.Log(ex);
context.Response.Redirect("/Error/ErrorPage");
}
How to determine where request was send? I mean how to get type of method which the request was sent to?
because I'd want to do something like typeof(targetMethod)
to determine whether it is e.g JsonResult
or not