ReInvoke ActionMethod in Exception Filter Class WebApi C#

21 Views Asked by At

I have created a custom ExceptionFilter to catch all exceptions of WebApi controller action method. Is it possible to get action method in the exception method and reinvoking it from there after doing required code fixing

Here is the code:

    public class ExceptionHandlerFilterAttribute : ExceptionFilterAttribute
{
    public override void OnException(HttpActionExecutedContext context)
    {
        try
        {
            var ex = context.Exception;
            string ControllerName = string.Format("{0}Controller-{1}", context.ActionContext.ControllerContext.ControllerDescriptor.ControllerName, context.ActionContext.ActionDescriptor.ActionName);
            SPConnection.InsertRecordToTableErrorLog(ex.Message, ex.StackTrace, ControllerName, ex.GetType().Name);

            **SPConnection.SharepointClientContext = null;**

            **// reinvoke ActionMethod here??**


            base.OnException(context);
        }
        catch (Exception ex) {
            throw ex;
        }
    }
}

Api Controller method which will throw unhandled exception:

        [Authorize]
    [HttpPost]
    [Route("update")]
    public HttpResponseMessage update(Update up)
    {
        bool result = _iMembersBL.Update(up);
        if (result)
            return Request.CreateResponse(HttpStatusCode.OK, "Success");
        else
            return Request.CreateResponse(HttpStatusCode.OK, "Failed");
    }
0

There are 0 best solutions below