Exemplo n.º 1
0
        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext.ExceptionHandled)
            {
                return;
            }
            HttpException he = filterContext.Exception as HttpException;

            if (he != null)
            {
                ResourceErrorActionResult rear;
                if (WebApiEnabledAttribute.TryGetErrorResult2(filterContext.RequestContext, he, out rear))
                {
                    if (rear != null)
                    {
                        filterContext.Result           = rear;
                        filterContext.ExceptionHandled = true;
                    }
                    return;
                }
                // if enumeration doesn't yield a handler the request is not acceptable
                // CONSIDER: returning all formats considered in the exception messages
                throw new HttpException((int)HttpStatusCode.NotAcceptable, "None of the formats specified by the accept header is supported.");
            }
        }
Exemplo n.º 2
0
                public override object Execute(ControllerContext controllerContext, IDictionary <string, object> parameters)
                {
                    HttpException             he = new HttpException((int)this.statusCode, this.message);
                    ResourceErrorActionResult rear;

                    if (!WebApiEnabledAttribute.TryGetErrorResult2(controllerContext.RequestContext, he, out rear))
                    {
                        rear = new ResourceErrorActionResult(new HttpException((int)this.statusCode, this.message), new ContentType("text/plain"));
                    }
                    return(rear);
                }