public override HttpActionDescriptor SelectAction(HttpControllerContext controllerContext) { HttpActionDescriptor decriptor = null; try { decriptor = base.SelectAction(controllerContext); } catch (HttpResponseException ex) { var routeData = controllerContext.RouteData; routeData.Values["action"] = "HandleError"; routeData.Values["statusCode"] = ex.Response.StatusCode; IHttpController httpController = new ApiErrorController(); controllerContext.Controller = httpController; controllerContext.ControllerDescriptor = new HttpControllerDescriptor(controllerContext.Configuration, "ApiError", httpController.GetType()); decriptor = base.SelectAction(controllerContext); } return(decriptor); }
public override HttpActionDescriptor SelectAction(HttpControllerContext controllerContext) { HttpActionDescriptor decriptor; try { decriptor = base.SelectAction(controllerContext); } catch (HttpResponseException ex) { HttpStatusCode code = ex.Response.StatusCode; if (code != HttpStatusCode.NotFound && code != HttpStatusCode.MethodNotAllowed) { throw; } System.Web.Http.Routing.IHttpRouteData routeData = controllerContext.RouteData; routeData.Values["action"] = "Handle404"; IHttpController httpController = new ApiErrorController(); controllerContext.Controller = httpController; controllerContext.ControllerDescriptor = new HttpControllerDescriptor(controllerContext.Configuration, "Error", httpController.GetType()); decriptor = base.SelectAction(controllerContext); } return(decriptor); }